/**************************************************************************
 * @doc CPACSRC
 * @module CPACOPER.C |
 * Source code for handling the custom operations
 * Product         :   SoftPay 2000 (Global Payment Methodology).
 * <nl>Developer   :
 * <nl>Notes       :
 * @head3 Custom Functions |
 * @index | Print
 * @end
 *
 * Copyright (c) 1996-2000 by VeriFone Inc. All rights reserved.
 *
 * No part of this software may be used, stored, compiled, reproduced,
 * modified, transcribed, translated, transmitted, or transferred, in any form
 * or by any means whether electronic, mechanical, magnetic, optical,
 * or otherwise, without the express prior written permission of VeriFone, Inc.
 *
 * Revision History
 * 27-Dec-2005			CHIA Lee Chyi					Check for Track 2 data is Track 1 is not available
 * ------------------------------------------------------------------------
 $Log: /SoftPay/SPK2SIM/Source/Print/cpacoper.c $
 *
 * ------------------------------------------------------------------------
 ********************************************************************************/

#ifdef IMAM_LOG
#ifndef LOGSYS_FLAG
#define LOGSYS_FLAG
#endif
#endif

#include <project.h>
#define CPAC_VPRINT_C

#include <aclconio.h>
#include <txoinc.h>
#include <ascii.h>
#include <errno.h>
#include <applidl.h>
#include <printer.h>
#include <formater.h>
#include <message.h>
#include <acldev.h>
#include <actutil.h>

/** /#define DEBUG_VSPRINT*/
#ifdef DEBUG_VSPRINT
#define DEBUG_95
#endif

#include <define.h>
#include <transact.h>
#include <print.h>
#include <gds.h>
#include <lct.h>
#include <tct.h>
#include <hdt.h>
#include <mht.h>
#include <pct.h>
#include <ui.h>
#include <msg.h>
#include <msgfuncs.h>
#include <form.h>
#include <stats.h>
#include <paramrpt.h>
#include <logo.h>
#include <tran.h>
#include <table.h>
#include <stdlib.h>
#include <aclstr.h>
#include <string.h>
//#include <beetle.h>
#include<test.h>

#include <spdebug.h>
#include <init.h>
#include <util.h>
#include <confio.h>
#include <oper.h>
#include <entry.h>
#include <file.h>
#include <card.h>
#include <cardmsg.h>
#include <funcids.h>
#include <accum.h>
#include <spamsg.h>
#include <multilng.h>
#include <format.h>
#include <date.h>
#include <ui.h>
#include <isoload.h>
#include <pbatch.h>
#include <cdt.h>
#include <settlbat.h>
#include <stats.h>
#include <menus.h>
#include <mit.h>
#include <tblutil.h>

#include <mdlfuncs.h>

#ifdef ICC_DEFINED // CPAC2.1B
#include <cardslot.h>
#endif
//#include <report.h>
#ifdef HKGM
#include <tip.h>
#endif /* HKGM */

#include "cpacoper.h"
#include "cpacmsg.h"
#include "cpacsize.h"
#include "sqautils.h"
//#include "cpacsrc.h" //leo_may1800
#include "cpac.h"
#include "cpacbat.h"
#include "custoper.h"
#include "cpacextn.h"
#include "cpacids.h"
#include "batmsg.h"

#ifdef ICICI
	#include "..\ICICSrc\ICICMsg.h"
#endif  /* ICICI */

#ifdef VXEMVAPP
#include "../EMVSrc/EMVMsg.h"
#endif /* VXEMVAPP */

#define CPAC_FILE_NAME                      "CPAC.DAT"
#define SIZE_CPAC_REC                   REC_SIZEOF(CPAC_REC)
#define STATS_DAY_REPORT    1
#define STATS_WEEK_REPORT   2
static const char* STATS_FRM1 = "STATS.FRM";

extern g_data gvardata[];
static int inVeriPrintHandle = -1;
extern int trancount;
extern VS_BOOL gfPPadPresent;
extern int inImamLineNumber;
#ifdef SHELL_FLEET
char szKbdBuf[CARD_SIZE + 1];

#endif
#ifdef VXEMVAPP
	extern long lnTranTitleMessage;
#endif /* VXEMVAPP */
static void vdCPACEntryDisplayAt(WIN_INFO* wi8x21Win,int inCol,int inRow,char* szDispBuf,int inClear);
static int inCPACGetHostTotals(TRANSACTION_OBJECT* pobTran,ACCUM_REC* psrHostTotals,int inHostIndex);
// CPAC_LINT_ADDED

extern void vdSetReportDateAndTime(void);
extern int inPrintStatsData(int inDay,STATS* psrStats);
extern int inOpenStatsHistory(int* inFHandle,STATS* psrStats);
extern int inGetDateTime(char* pszDateTime);
extern void vdFormatCITIDate(char* pchDate);
extern void vdLoadCPACParams(CPAC_REC* psrCPAC);  //CPAC_AMEX added.
extern char* szGetTracks(void); //1.4
extern short shGetTransactionCode(TRANSACTION_OBJECT* pobTran);
extern void vdCPACGetMessageFromReceiptFile(long lnMessageIndex,char* szMessageBuffer,TRANSACTION_OBJECT* pobTran);
extern int inGlobalMerchantHandle;
/* #ifdef TLFB  (Saritha_b1......moving out TLFB switch )
 extern int inTLFBGetHostNum(TRANSACTION_OBJECT *pobTran);
#endif  */  /* TLFB */  //  (Saritha_b1......moving out TLFB switch )

#define CPAC_CHOICE_INV                         1
#define CPAC_CHOICE_ACCT                               2
#define ACCESS_WITH_SUPER_PASSWORD              2

#if 0
short (*shIdFns1[])(short, short) = //1.4 added short, short for LINT
{
    default_init, /* default init */
    p3300_id,     /* P3300   ,,   */
};

int inSetCPACStatusLine (void)
{
    if (getgrid() != 0)
        obDisp.inStatusLine = 7;
    return (VS_SUCCESS);
}

#endif /* 0 */

int inCustDisplaySwipeCardInfo(TRANSACTION_OBJECT* pobTran) {
#ifndef IMAM_REMOVE
    char szFormattedPAN[FORMATTED_PAN_SIZE + 1];
    int inMsgLen,
    inFmtPANLen,
    inGrid,
    inFontType;
    char szMsg[MESSAGE_SIZE + 1],
    szAccountNumber[PAN_SIZE + 1];
	char buff[10];

	memset(buff, 0x00, sizeof(buff));
    memset(szFormattedPAN, 0x00, FORMATTED_PAN_SIZE + 1);
    vdClear_8X21_Window(1, 3, 21, inImamLineNumber);
    strcpy(szAccountNumber, pobTran->srBRec.szPAN);
#ifndef HKGM
#else
    strcpy(szFormattedPAN, szAccountNumber);
#endif /* HKGM */
    vdFormatPAN(pobTran, szAccountNumber, szFormattedPAN, sizeof(szFormattedPAN));

  

    vdGetMessageFromFile(CPAC_PAN_MESSAGE, szMsg);
    inMsgLen = strlen(szMsg);
    inFmtPANLen = strlen(szFormattedPAN);

    inGrid = getgrid();
    inFontType = get_font_mode();

    if (inGrid == 0) {
        vdDisplayAt(obDisp.inHomeCol, 3, szMsg, CLR_EOL);
        vdDisplayAt_ASC8X21((22 - (strlen(szFormattedPAN))), 7, szFormattedPAN, NO_CLEAR);
    } else {
		{   //LIEM to display card holder name
			char szCardHolder[CHOLDER_SIZE * 2 + 1];
			strcpy(szCardHolder, pobTran->srBRec.szCHolder);
			vdTrimLeadSpaces(szCardHolder);
			szCardHolder[21] = 0x00;
			vdTrimSpaces(szCardHolder);
			if (strlen(szCardHolder)>1) vdDisplayAt((22 - (strlen (szCardHolder))), inImamLineNumber-3, szCardHolder, CLR_EOL); 
		}	
		//vdDisplayAt(obDisp.inHomeCol, 5, szMsg, CLR_EOL); //
   	    vdDisplayAt(1, inImamLineNumber-2, "PAN:", CLR_EOL);
		
		if (strlen (szFormattedPAN) > 17) inImamCustScroll(pobTran);
		if (strlen (szFormattedPAN) > 21) {
			strcpy(szFormattedPAN, &szFormattedPAN[strlen(szFormattedPAN)-21]); 
			szFormattedPAN[21] = 0x00;
		}
		
	    	/* Edi -  wongslam - disable screen pan formated */
    		{
			memset(buff, 0x00, sizeof(buff));
			get_env_x("MASKING.SCREEN", 0, buff);
			if (atoi(buff)) {
				vdDisplayAt((22 - (strlen (szFormattedPAN))), inImamLineNumber-2, szFormattedPAN, CLR_EOL);
			} else {
				vdDisplayAt((22 - (strlen (szAccountNumber))), inImamLineNumber-2, szAccountNumber, CLR_EOL);
			}
    		}
		/*****************************************/
		
		vdDisplayAt(1, inImamLineNumber-1, "EXP[MMYY]:", CLR_EOL);
		memset(buff, 0x00, sizeof(buff));
		strncat(buff, &pobTran->srBRec.szExpDate[2], 2);
		strncat(buff, &pobTran->srBRec.szExpDate[0], 2);
		vdDisplayAt((22 - (strlen (buff))), inImamLineNumber-1, buff, CLR_EOL);
		//inImamCustScroll();  //
    }
#endif //IMAM_REMOVE
    return (VS_SUCCESS);
}


int inCPACDisplayCardTitle(TRANSACTION_OBJECT* pobTran) {
    char szCardLabel[CLABEL_SIZE + 1];

	inCITIDisplayAppLabel(pobTran);

    /*if (pobTran->srBRec.inTranCardType == DEBIT_CARD)
              vdGetMessageFromFile( DEBIT_MSG, szCardLabel);
        else*/
    strcpy(szCardLabel, szGetCardLabel());
    //  vdGetCardLabel(szCardLabel);

    //if (strlen(szCardLabel) > 6) szCardLabel[6] = 0x00;
	szCardLabel [CLABEL_SIZE] = 0x00;  //

    vdDisplayDataStr(szCardLabel, 1, NO_CLEAR, ML_RIGHT);
#if 0
        if ( obDisp.blActionFontASC8x21 )
            vdDisplayAt(obDisp.inHomeCol, obDisp.inTitleLine, szCardLabel, NO_CLEAR);
        else
            vdDisplayAt_ASC8X21(obDisp.inHomeCol, obDisp.inTitleLine, szCardLabel, NO_CLEAR);
#endif /* 0 */
    /* sprintf(pobTran->srBRec.szIssueNumber,"%02d", inGetIssuerNumber()); */
    /* vdDisplayAt(1,1, pobTran->srBRec.szIssueNumber, CLR_EOL); get_char(); */
    return (VS_SUCCESS);
}



/*********************************************************************************************
* @func int | inCPACStartCardTxn |
*
* This function starts a card based or manual entry based transaction with the
* approp: messages.
*
* @parm void    | TRANSACTION_OBJECT |
*
* @rdesc Return values.
* @ VS_SUCCESS  |  VS_SUCCESS   |
* @ VS_ERROR    |  VS_ERROR     |
* @end
**********************************************************************************************/

int inCPACStartCardTxn(TRANSACTION_OBJECT* pobTran) {
#ifndef IMAM_REMOVE
    char szMessage[MESSAGE_SIZE + 1];


    if ((inGGCode() != SALE) && (CHK_CARD_RDR() != 0))   // Clear any pending mag swipe data
    {
        // Only if not the SALE
        vdFlushCardBuffer();
    }

    if ((inGGCode() != PHONE) && (CHK_CARD_RDR() == 0)
#ifdef ICC_DEFINED // 1.4
        && (Get_Card_State(CUSTOMER_CARD) != CARD_PRESENT)
#endif
       ) {
        vdClearASCII8x21Window(1, 3, 21, 8);  // Clear the screen except the trn name
			#ifdef VXEMVAPP
			if((lnTranTitleMessage == SALE_MSG) ||(lnTranTitleMessage == AUTH_ONLY_ITEM_MSG15) ||
				(lnTranTitleMessage == PRE_AUTH_MSG) || (lnTranTitleMessage == IMAM_CARDVER_MSG) || (lnTranTitleMessage == REFUND_OFFLINE_MSG) )
				vdGetMessageFromFile(EMV_INSERT_MSG, szMessage);
			else
			#endif /* VXEMVAPP */
        vdGetMessageFromFile(SWIPE_MSG, szMessage);
        if (getgrid() == 0)
            vdDisplayAt(1, 2, szMessage, CLR_EOL);
        else
            vdDisplayAt(1, 3, szMessage, CLR_EOL);
    }

    if (CHK_CARD_RDR() == 0
#ifdef ICC_DEFINED //1.4
        && (Get_Card_State(CUSTOMER_CARD) != CARD_PRESENT)
#endif
       ) {
        vdGetMessageFromFile(CPAC_PAN_MESSAGE, szMessage);
        if (getgrid() == 0)
            vdDisplayAt(1, 3, szMessage, CLR_EOL);
        else
            vdDisplayAt(1, 5, szMessage, CLR_EOL);
    }

    vdClear_8X21_Window(1, 8, 21, 8);
    if (getgrid() == 0)
        vdClear_8X21_Window(1, 7, 21, 8);   // clear the seventh line also
#endif //IMAM_REMOVE
    return (VS_SUCCESS);
}



/*********************************************************************************************
* @func int | inCPACAdjust |
*
* This function sets the fAdjust which is otherwise not set during an adjust from Main menu.
* approp: messages.
*
* @parm void    | TRANSACTION_OBJECT |
*
* @rdesc Return values.
* @ VS_SUCCESS  |  VS_SUCCESS   |
* @ VS_ERROR    |  VS_ERROR     |
* @end
**********************************************************************************************/

int inCPACAdjust(TRANSACTION_OBJECT* pobTran) {
    pobTran->fAdjust = VS_TRUE;
    return VS_SUCCESS;
}

/*-------------------------------------------------------------------------
    Function :  inCPACAboutFileProcessing()
    Description : About File Processing Functionality

    Modification History :
      #     Date      Who                     Description
    ----- -------- ---------- ---------------------------------------------
--------------------------------------------------------------------------*/
int inCPACAboutFileProcessing(TRANSACTION_OBJECT* pobTran) {
    char szMessage[(MESSAGE_SIZE*3)];
    char szDisplay[MESSAGE_SIZE];
    int inResult,
    inFldIdx,
    inRowOffset;
    //   int        inTopLeftX, inTopLeftY, inBotRightX, inBotRightY;
    //  char szCurFontFile [FILENAME_SIZE + 1];

    FHANDLE hFHandle;

    if ((hFHandle = open("about.txt", O_RDONLY)) < 0)
        return(VS_ERR);

    memset(szMessage, 0x00, sizeof(szMessage));

    inResult = read(hFHandle, szMessage, sizeof(szMessage));
    if (inResult == VS_ERROR)              /* Error reading record info */ {
        close(hFHandle);
        return(VS_ERR);
    }
    close(hFHandle);

    /*
     *      Strip text editor trash from the end of the file
     */
    while (szMessage[strlen(szMessage) - 1] < ' ')
        szMessage[strlen(szMessage) - 1] = NULL_CH;
    vdClearNonTitleLines();

    inDisplayCustLogo(12, 1, "F:SPTLOGO.VFT", 5, 1, CHARS_8X16, 8);

    inRowOffset = 2;

    for (inFldIdx = 1; inFldIdx <= 2; ++inFldIdx) {
        memset(szDisplay, 0, sizeof(szDisplay));
        fieldvar(szMessage, inFldIdx, ':', szDisplay);
        vdDisplayDataStr(szDisplay, inFldIdx + inRowOffset++, NO_CLEAR, ML_LEFT);
    }

    strcpy(szDisplay, "As on: ");
    strcat(szDisplay, __DATE__);
    vdDisplayDataStr(szDisplay, 7, CLR_EOL, ML_LEFT); {
        char* szUs[9] = {
            "\x4B\x65\x6C\x76\x69\x6E",
            "\x4B\x72\x69\x73\x68\x6E\x61",
            "\x4C\x65\x6E\x69\x6E",
            "\x4C\x65\x6F\x6E",
            "\x4C\x75\x69",
            "\x4D\x61\x6E\x6F\x6A",
            "\x52\x61\x6A\x61\x72\x61\x6D",
            "\x53\x61\x64\x69\x71",
            "\x56\x69\x70\x69\x6E"
        };
        int inKey,
        i,
        inJ;
        inKey = get_char();
        if (inKey == 0x02)
            inRunOperation(pobTran, CPAC_ERR_REPORT_OPERATION);

        if (inKey == 0x03)
            inRunOperation(pobTran, CPAC_HANDLES_OPERATION);

        if (inKey == 0x01) {
            inKey = get_char();
            if (inKey == 0x04) {
                inKey = get_char();
                if (inKey == 0x02) {
                    inKey = get_char();
                    if (inKey == 0x03) {
                        for (i = 1; i <= 4; i++) {
                            for (inJ = 11; inJ >= 1; inJ -= 5) {
                                inDisplayCustLogo(inJ, i, "F:SPTLOGO.VFT", 5, 1, CHARS_8X16, 8);
                                vdDelay(200);
                                inMLDisplayAt(inJ, i, " ", CLR_EOL, ML_USE_GIVEN_FONT, ML_MENU_FONT, ASC4X16_VFT);
                            }
                        }
                        vdBeep();
                        vdBeep();
                        clrscr();
                        while (!KBHIT()) {
                            inDisplayCustLogo(1, 1, "F:SPTLOGO.VFT", 16, 1, CHARS_8X16, 8);
                            inDisplayCustLogo(1, 4, "F:SPTLOGO.VFT", 16, 1, CHARS_8X16, 8);
                            inMLDisplayAt(7, 4, "Asia Team", CLR_EOL, ML_USE_GIVEN_FONT, ML_MENU_FONT, ASC4X16_VFT);
                            for (i = 0; i <= 8; i++) {
                                inMLDisplayAt(1, 4, szUs[i], CLR_EOL, ML_USE_GIVEN_FONT, ML_MENU_FONT, ASC8X21_VFT);
                                vdDelay(200);
                                inMLDisplayAt(1, 2, szUs[i], CLR_EOL, ML_USE_GIVEN_FONT, ML_MENU_FONT, ASC4X16_VFT);
                                vdDelay(200);
                                inMLDisplayAt(1, 2, szUs[i], CLR_EOL, ML_USE_GIVEN_FONT, ML_MENU_FONT, ASC4X8_VFT);
                                vdDelay(250);
                                vdClearASCII8x21Window(1, 3, 21, 6);
                            }
                        }
                    }
                }
            }
        }
        //          else get_char ();
    }
    return(BRANCH_EXIT);
} /* End of inCPACAboutFileProcessing () */

int inCPACManualEntryProcess (TRANSACTION_OBJECT *pobTran, PFI_TO_PSZ pinValManual, int *pinResult)
{

	int inStatus;
	char szAccountNumber[PAN_SIZE + 1];
	char chExpDate[EXP_DATE_SIZE + 1], szTemp[EXP_DATE_SIZE + 1];
	char szCPACMessage [MESSAGE_SIZE + 1];

        vdSetNextLineEntry(); /* force entry on line after prompt */

		if (getgrid() == 0)  // CPAC_ML
            *pinResult = inCPACEnterWithMessage(CPAC_PAN_MESSAGE, SCROLL_DISPLAY_FALSE, 3, 7,
                                            szAccountNumber, INPUT_NUMS, PAN_SIZE, NULL);
        else
            *pinResult = inCPACEnterWithMessage(CPAC_PAN_MESSAGE, SCROLL_DISPLAY_FALSE, 5, inImamLineNumber-1,
                                            szAccountNumber, INPUT_NUMS, PAN_SIZE, NULL);

        if (*pinResult >= 0)
        {
			*pinResult = pinValManual(pobTran, szAccountNumber);
            if (*pinResult >= 0)
            {
				strcpy(pobTran->srBRec.szPAN, szAccountNumber);
            	/* Form the Last 4 Acct # to Key Structure */
            	pobTran->srBKey.lnLast4 = str2long (&pobTran->srBRec.szPAN[strlen(pobTran->srBRec.szPAN) - LAST4_DIGIT_ACCT]);
            }
		}
		else
		{
			inStatus = *pinResult;
			return(inStatus);
		}

        memset(chExpDate, NULL_CH, sizeof(chExpDate));
        memset(szTemp, NULL_CH, sizeof(szTemp));

		if ((*pinResult >= 0) /* && fGetExpDtReqd() */ )
		{

            if (getgrid() == 0)  // CPAC_ML   CPAC_AMEX
                *pinResult = inCPACEnterWithMessage(EXPDATE_MSG17, SCROLL_DISPLAY_TRUE, 3, 7, chExpDate, INPUT_NUMS, EXP_DATE_SIZE, inCPACValidateManualExpDate);
            else				// CPAC_AMEX
				{   // to display PAN when manual entry
					vdDisplayAt(1, inImamLineNumber-3, " ", CLR_EOL);
					vdClearNonTitleLines ();
					vdDisplayAt(1, inImamLineNumber-1, "PAN:", CLR_EOL);  
					vdDisplayAt(22-strlen(pobTran->srBRec.szPAN), inImamLineNumber-1, pobTran->srBRec.szPAN, CLR_EOL);
				}
                *pinResult = inCPACEnterWithMessage(EXPDATE_MSG17, SCROLL_DISPLAY_TRUE, inImamLineNumber-1, inImamLineNumber-1, chExpDate, INPUT_NUMS, EXP_DATE_SIZE, inCPACValidateManualExpDate);

			strcpy(pobTran->srBRec.szExpDate, chExpDate);

			/*memcpy (szTemp, &chExpDate[2], 2);   // swapping MM & YY - MAL requirements.
			memcpy (&szTemp[2], chExpDate, 2);
			szTemp[4] = 0x00;
	        strcpy(pobTran->srBRec.szExpDate, szTemp); */
		}
		if (*pinResult < 0)
        {
			if (lnGGErrorMessage())
            {
				if(*pinResult != VS_ESCAPE)
				{
					vdDisplayMessageFromFile( lnGGErrorMessage(), WARNING_MSG);
					vdClearNonTitleLines ();
					vdFlushCardBuffer();  /// added to flush any pending card swipes CPAC_+
					vdFlushKeyboardBuffer(); // VK 9 1.4
				}
				vdSGErrorMessage(0L);

                if (inGGCode() != PHONE)
                {
					vdGetMessageFromFile (SWIPE_MSG, szCPACMessage);
					if (getgrid() == 0)  // CPAC_ML
                        vdDisplayAt (1, 2, szCPACMessage, CLR_EOL);
                    else
                        vdDisplayAt (1, 3, szCPACMessage, CLR_EOL);
				}
				vdGetMessageFromFile (CPAC_PAN_MESSAGE, szCPACMessage);
     	        if (getgrid() == 0)  // CPAC_ML
                    vdDisplayAt (1, 3, szCPACMessage, CLR_EOL);
                else
                    vdDisplayAt (1, 5, szCPACMessage, CLR_EOL);
			}
		}
        else
        {
			if ( fGetManEntry() )
            {
				if ( fGetManEntryPasswd() )
                {
					do
					{
						*pinResult = inGetPwdFromUser (ACCESS_WITH_SUPER_PASSWORD,NO_PIT_INDEX);
						//*pinResult = inGetAndValSuperManPwds(BOTH_PW);
						if (*pinResult == VS_ERR)
    	                {
        					if (lnGGErrorMessage())
        	                {
            					vdDisplayMessageFromFile( lnGGErrorMessage(), WARNING_MSG);
            	                vdClearStatusMessage();
            	                vdSGErrorMessage(0L);
							}
						}
					} while((*pinResult != VS_ESCAPE) && (*pinResult != VS_SUCCESS));
				}
			}
            else
            {
				vdDisplayMessageFromFile( MAN_ENTRY_MSG21, WARNING_MSG);
                *pinResult = VS_ESCAPE;
			}
		}

	#ifdef ICICI
        	switch(pobTran->srBRec.inCode)
		{
			case PRE_AUTH:
			case IMAM_CARDVER:
			case AUTH_ONLY:
							if(fGetCDTCustomBit1() == VS_FALSE)
							{
								vdSGErrorMessage(TRANS_NOT_ALLWD_ERR_MSG);
								return (VS_ERR);
							}
							break;
			/*case SALE_OFFLINE:
							if(fGetCDTCustomBit2() == VS_FALSE)
							{
								vdSGErrorMessage(TRANS_NOT_ALLWD_ERR_MSG);
								return (VS_ERR);
							}
							break;
			case REFUND:
							if(fGetCDTCustomBit3() == VS_FALSE)
							{
								vdSGErrorMessage(TRANS_NOT_ALLWD_ERR_MSG);
								return (VS_ERR);
							}
							break;*/
		}

	#endif  /* ICICI  */
	return (VS_SUCCESS);
}

/*********************************************************************************************
* @func int | inCPACValidateManualExpDate |
*
*       The expiry date validation routine (inValExpDate) expects the expiry
*       date in YYMM form. This data is stored in card track in YYMM format,
*       but the user enters it usually in MMYY format, so swap bytes 1 and 2
*       with bytes 3 and 4.
*            CPAC_AMEX added
* @parm char *  | pchExpDate    |
*
* @rdesc Return values.
* @flag int    |  VS_SUCCESS    |
* @flag int    |  VS_ERR        |
* @end
**********************************************************************************************/

int inCPACValidateManualExpDate(char* pchExpDate) {
    char chSwapper;

    /**/pdebug(("--inValidateManualExpDate(%s)--", pchExpDate));/**/
    if (strlen(pchExpDate) != EXP_DATE_SIZE) {
        vdSGErrorMessage(INV_DATE_ERR_MSG);
        return (VS_ERR);
    }

    chSwapper = pchExpDate[0];
    pchExpDate[0] = pchExpDate[2];
    pchExpDate[2] = chSwapper;
    chSwapper = pchExpDate[1];
    pchExpDate[1] = pchExpDate[3];
    pchExpDate[3] = chSwapper;
    if (!fGetExpDtReqd())
        return(VS_SUCCESS);
    return(inCPACValidateExpDate(pchExpDate));
}

/*********************************************************************************************
* @func int | inCPACValidateExpDate |
*            Check the validity of the date. The function addresses the 21st Century
*            and leap years. Also, the expiration day-of-month computed to be the
*            last day of the given month.
*            CPAC_AMEX added
* @parm char * | szDateEntered |
*        Pointer to buffer containing date
*
* @rdesc
* @flag int | VS_SUCCESS
* @flag int | VS_ERR
* @end
**********************************************************************************************/
int inCPACValidateExpDate(char* szDateEntered) {
    int inEnteredDate,
    inPOSDate,
    inWday,
    inSec,
    inMin,
    inHour,
    inDay,
    inMon,
    inPOSYear,
    inEnteredYear,
    inStatus = VS_SUCCESS;
    char szCentury[CENTURY_SIZE + 1],
    szTempDate[DATE_SIZE + 1],
    szPOSDateAndTime[COMPLETE_DATE_AND_TIME_SIZE + 1],
    szCardLabel[CLABEL_SIZE + 1];


    pdebug(("--inValidateExpDate--"));

    sprintf(szTempDate, "%.2s%.2s", &(szDateEntered[2]), &(szDateEntered[0]));
    vdGetCentury(&(szTempDate[2]), szCentury);
    pdebug(("Century = %2s", szCentury));

    sprintf(szTempDate, "%s%.2s", szCentury, &(szDateEntered[0]));
    pdebug(("TempDate = %s", szTempDate));

    inMon = atoi(&(szDateEntered[2]));
    if ((inMon > MAX_MONTHS_IN_YEAR) || (inMon < MIN_MONTHS_IN_YEAR)) {
        vdSGErrorMessage(INV_DATE_ERR_MSG);
        return VS_ERR;
    }

    strcpy(szCardLabel, szGetCardLabel());
    //  vdGetCardLabel(szCardLabel);    /* AMEX expiry date checking not required JD */


    inEnteredYear = atoi(szTempDate);
    inDay = month_end(inMon, inEnteredYear);
    inEnteredDate = julian_date(inEnteredYear, inMon, inDay);

    SVC_CLOCK(GET_CLOCK, (char *) szPOSDateAndTime, COMPLETE_DATE_AND_TIME_SIZE);

    if (clock2int(NO_CLOCK_HANDLE(unsigned char *)szPOSDateAndTime, &inPOSYear, &inMon, &inDay, &inHour, &inMin, &inSec, &inWday) < 0) {
        vdSGErrorMessage(EXP_CARD_ERR_MSG21);
        return VS_ERR;
    }

    inPOSDate = julian_date(inPOSYear, inMon, inDay);
    pdebug(("inPOSYear = %d", inPOSYear));
    pdebug(("inEnteredYear = %d", inEnteredYear));
    if (inPOSYear > inEnteredYear)
        inStatus = VS_ERR;
    else if (inPOSYear == inEnteredYear) {
        if (inPOSDate > inEnteredDate)
            inStatus = VS_ERR;
    }
    if (inStatus == VS_ERR)
        vdSGErrorMessage(EXP_CARD_ERR_MSG21);

    return(inStatus);
}
int inCPACEnterWithMessage(long lnMessageNumber,VS_BOOL fScrollDisplay,int inPromptRow,int inEntryRow,char* szResponseString,int inDataType,int inMaxChars,int  (*inValidator) (char* szResponseString)) {
    char szMessage[MESSAGE_SIZE + 1];

    vdGetMessageFromFile(lnMessageNumber, szMessage);

    *szResponseString = NULL_CH;

    return (inCPACEnterWithStrDefault(lnMessageNumber, ((lnMessageNumber != EMPTY_STR_ERR_MSG) ? szMessage : NULL_CH), fScrollDisplay, inPromptRow, inEntryRow, szResponseString, inDataType, inMaxChars, inValidator));
}


int inCPACEnterWithStrDefault(long lnMsgId,char* szPromptString,VS_BOOL fScrollDisplay,int inPromptRow,int inEntryRow,char* szResponseString,int inDataType,int inMaxChars,int (*inValidator) (char* szResponseString)) {
    char szAst[1 + 1];
    char szLocBuf[1 + 1];

    int inLeft,
    inTop,
    inRight,
    inBottom,
    inResult = 0;
    int inValidResponse;
    int inChar,
    inCharOffset = 0,
    inNewLine = FALSE,
    inCharsPastDisplay;
    int inFieldVisibleWidth;
    VS_BOOL fNegativeValue = FALSE,
    fInitialKeyPress = TRUE;
    int inTermCharsPerRow;
    int inPromptTermCharsPerRow;

    WIN_INFO wiCur8x21Win;

    szAst[0] = '*'; szAst[1] = 0;
    strcpy(szLocBuf, " ");

    /*
     *  determine if entry is on current
     *  or current+1 line....
     */
    //    inEntryRow = 7;
    //    vdSetEntryRow(&inEntryRow, lnMsgId);
    inPromptTermCharsPerRow = inTermCharsPerRow = inGetRowLim();
    if (!obDisp.blActionFontASC8x21)
        vdCalculateCoord(GRID_4x8_TO_8x21, &inTermCharsPerRow, &inEntryRow);
    inFieldVisibleWidth = inTermCharsPerRow;

    wherewin(&inLeft, &inTop, &inRight, &inBottom);
    if (szPromptString)
        vdScrollDataEntry(fScrollDisplay);

    if ((!obDisp.blCfigEdit) && (!obDisp.blEntryNextLine)) {
        /*
         *  not config edit, or entry on the
         *  next line, so apply normal rule...
         */
        if (szPromptString)
            inFieldVisibleWidth = inTermCharsPerRow - strlen(szPromptString);
    }

    if (inMaxChars < inFieldVisibleWidth)
        inFieldVisibleWidth = inMaxChars;

    do {
        if (szPromptString) {
            /*
                 *      Clear Entry Lines & Display Prompt
                 */
            //          vdClearEntryLines (inTermCharsPerRow);

            if (getgrid() == 0)  // CPAC_ML
                vdClear_8X21_Window(1, 5, 21, 8);
            else
				vdClear_8X21_Window(1, inImamLineNumber-1, 21, inImamLineNumber);  // 
                //vdClear_8X21_Window(1, 6, 21, 8);  

            vdDisplayAt(obDisp.inHomeCol, inPromptRow, szPromptString, NO_CLEAR);
            window(inLeft, inTop, inRight, inBottom);
        }

        /*
         *      Handle existing data in response buffer.
         */
        fInitialKeyPress = TRUE;

        /* Setup entry window */
        wiCur8x21Win.inLeft = inTermCharsPerRow - inFieldVisibleWidth + 1;
        wiCur8x21Win.inTop = wiCur8x21Win.inBottom = inEntryRow;
        wiCur8x21Win.inRight = inTermCharsPerRow ;
        if (obDisp.blActionFontASC8x21)
            window(wiCur8x21Win.inLeft, wiCur8x21Win.inTop, wiCur8x21Win.inRight, wiCur8x21Win.inBottom);

        if (*szResponseString) {
            inCharOffset = strlen(szResponseString);
            if ((inFieldVisibleWidth <= inMaxChars) && (inCharOffset > inFieldVisibleWidth)) {
                inCharsPastDisplay = inCharOffset - inFieldVisibleWidth;
                vdCPACEntryDisplayAt(&wiCur8x21Win, obDisp.inHomeCol, obDisp.inTitleLine, szResponseString + inCharsPastDisplay, NO_CLEAR);
            } else
                vdCPACEntryDisplayAt(&wiCur8x21Win, inFieldVisibleWidth - inCharOffset + 1, obDisp.inCharsPerColumn - 1, szResponseString, CLR_EOL);
        }

        while (((inChar = inWaitKey(inGetIdleTimeOut())) != KEY_CR) && (inChar != KEY_CANCEL)) // BJD: KEY_CLR -> KEY_CANCEL
        {
            if (fInitialKeyPress) {
                *szResponseString = NULL_CH;
                inCharOffset = 0;
                vdCPACEntryDisplayAt(&wiCur8x21Win, obDisp.inHomeCol, obDisp.inCharsPerColumn - 1, szResponseString, CLR_EOL);
            }
            fInitialKeyPress = FALSE;
            switch (szResponseString[inCharOffset] = (char) inChar) {
            case KEY_BS:
                if (inCharOffset) {
                    if (inFieldVisibleWidth >= inCharOffset) {
                        //vdDisplayAt(inFieldVisibleWidth - inCharOffset + 1, obDisp.inTitleLine, szLocBuf, NO_CLEAR );
                        vdCPACEntryDisplayAt(&wiCur8x21Win, inFieldVisibleWidth - inCharOffset + 1, obDisp.inTitleLine, " ", NO_CLEAR);
                    }

                    --inCharOffset;
                } else
                    vdBeep();
                break;

            case KEY_CLR:
                if (inCharOffset) {
                    szResponseString[0] = '\0';
                    inCharOffset = 0;
                    vdCPACEntryDisplayAt(&wiCur8x21Win, obDisp.inHomeCol, obDisp.inCharsPerColumn - 1, szResponseString, CLR_EOL);
                } else    // No characters entered yet
                    vdBeep();
                break;
            case KEY_a:
            case KEY_b:
            case KEY_c:
            case KEY_d:
            case KEY_e:
            case KEY_f:
            case KEY_g:
            case KEY_h:
                vdBeep();
                continue;

            case KEY_ALP:
                if ((inDataType == INPUT_ALNUMS) || (inDataType == INPUT_ALNUMS_PWD)) {
                    if (inCharOffset) {
                        inChar = chGetAlphaKey(szResponseString[inCharOffset - 1]);
                        szResponseString[inCharOffset - 1] = (char) inChar;
                    } else
                        vdBeep();
                } else {
                    if (fNegativeValue == VS_FALSE) {
                        if (strlen(szResponseString) < (unsigned) inMaxChars)
                            fNegativeValue = VS_TRUE;
                        else
                            vdBeep();
                    } else {
                        fNegativeValue = VS_FALSE;
                        vdCPACEntryDisplayAt(&wiCur8x21Win, inFieldVisibleWidth - inCharOffset + 1, obDisp.inTitleLine, "  ", NO_CLEAR);
                    }
                }
                break;

            default:
                if ((inCharOffset < inMaxChars) && (((inDataType == INPUT_FLAG) && ((inChar == '0') || (inChar == '1'))) || ((inDataType != INPUT_FLAG) && ((inDataType != INPUT_NUMS && inDataType != INPUT_NUMS_PWD) || ((inChar != KEY_STR) && (inChar != KEY_PND))))))
                    ++inCharOffset;
                else
                    vdBeep();
            }
            szResponseString[inCharOffset] = '\0';
            if ((inDataType == INPUT_NUMS_PWD) || (inDataType == INPUT_ALNUMS_PWD)) {
                if (inChar != KEY_BS)
                    vdCPACEntryDisplayAt(&wiCur8x21Win, inFieldVisibleWidth - inCharOffset + 1, obDisp.inTitleLine, szAst, NO_CLEAR);
            } else {
                if ((inFieldVisibleWidth <= inMaxChars) && (inCharOffset > inFieldVisibleWidth)) {
                    inCharsPastDisplay = inCharOffset - inFieldVisibleWidth;
                    vdCPACEntryDisplayAt(&wiCur8x21Win, obDisp.inHomeCol, obDisp.inTitleLine, szResponseString + inCharsPastDisplay, NO_CLEAR);
                } else
                    vdCPACEntryDisplayAt(&wiCur8x21Win, inFieldVisibleWidth - inCharOffset + 1, obDisp.inCharsPerColumn - 1, szResponseString, CLR_EOL);
            }
        }
        szResponseString[inCharOffset] = '\0';
        if (inChar == KEY_CANCEL)
            inResult = VS_ESCAPE;
        else
            inResult = inCharOffset;
        window(inLeft, inTop, inRight, inBottom);

        inValidResponse = inResult;
        if (inValidResponse >= 0) {
            if (inValidator) {
                //vdResetEntryFont (VS_FALSE);
                if ((inValidResponse = (*inValidator) (szResponseString)) == VS_ERR) {
                    vdDisplayMessageFromFile(lnGGErrorMessage(), WARNING_MSG);
                    vdSGErrorMessage(0L);
                    *szResponseString = NULL_CH;
                }
                //vdSetEntryFont (VS_FALSE);
            }
            /** /pdebug(("inResult=%d", inResult));*/
        }
    } while (inValidator && (inValidResponse == VS_ERR));

    /** /pdebug(("szResponseString=%s", szResponseString));*/
    window(inLeft, inTop, inRight, inBottom);
    if (!obDisp.blEntryNextLine)
        vdClearStatusMessage();

    if (obDisp.blCfigEdit) {
#if 0
    /* remove prompt and entry */
    window(obDisp.inHomeCol, (inEntryRow-1), inTermCharsPerRow, inEntryRow);
    clrscr();
    window(inLeft, inTop, inRight, inBottom);
#endif
        // ??? vdClearEntryLines (inTermCharsPerRow);
        vdClear_8X21_Window(1, 6, 21, inImamLineNumber);

        window(inLeft, inTop, inRight, inBottom);
    }

    if (obDisp.blEntryNextLine)
        obDisp.blNextLineCleanup = VS_TRUE;
    else
        obDisp.blNextLineCleanup = VS_FALSE;

    vdClrNextLineEntry();
    return(inResult);
}


static void vdCPACEntryDisplayAt(WIN_INFO* wi8x21Win,int inCol,int inRow,char* szDispBuf,int inClear) {
    int inLeft,
    inTop,
    inRight,
    inBottom;
    char szFontName[FILENAME_SIZE + 1];

    if (obDisp.blActionFontASC8x21)
        vdDisplayAt(inCol, inRow, szDispBuf, inClear);
    else {
        //int   inDummyCol;   CPAC_LINT_REMOVED

        wherewin(&inLeft, &inTop, &inRight, &inBottom);
        get_font(szFontName);
        set_font(ASC8X21_VFT);
        window(wi8x21Win->inLeft, wi8x21Win->inTop, wi8x21Win->inRight, wi8x21Win->inBottom);
        vdDisplayAt(inCol, inRow, szDispBuf, inClear);
        set_font(szFontName);

        window(inLeft, inTop, inRight, inBottom);
    }
}



int inCPACCardReadOperation(TRANSACTION_OBJECT* pobTran,PFI_TO pinValSwiped,int* pinResult) {
#ifndef IMAM_REMOVE
    int inAmtInputLine;  // inStatus,   CPAC_LINT_REMOVED
    char szNull[21 + 1],
    szCPACMessage[MESSAGE_SIZE + 1];
    PFI_TO pinMyFn;  //1.4 modified to PFI_TO

    if (getgrid() == 0)
        inAmtInputLine = 3;
    else
        inAmtInputLine = 7;

    memset(szNull, NULL_CH, sizeof(szNull));

    *pinResult = pinValSwiped(pobTran);

    if (*pinResult == VS_SUCCESS) {
        if ((inGetPrinterType() == NOPRINTER || !fGetEnablePrinter()) && (pobTran->srBRec.inTranCardType == DEBIT_CARD || pobTran->srBRec.inTranCardType == EBT_CARD)) {
            vdDisplayMessageFromFile(TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
            return(VS_ERR);
        }

        if ((pinMyFn = inGetFunctionPointer(DISPLAY_SWIPE_CARD_INFO)) == NULL_PFI)
            return(VS_ERR);
        if (pinMyFn(pobTran) == VS_ERR)
            return (VS_ERR);
    } else {
        if (lnGGErrorMessage()) {
            vdDisplayMessageFromFile(lnGGErrorMessage(), WARNING_MSG);
            if (obDisp.inTitleLine == obDisp.inStatusLine || obDisp.inTitleLine == obDisp.inInputLine)
                clrscr();
            if (obDisp.inTerminalType == TERMINAL_OMNI_3200) {
                char szNull[21 + 1];

                memset(szNull, NULL_CH, sizeof(szNull));
                if ((getgrid() == 0) && (get_font_mode() == 2)) // 2 byte addressing scheme + 16x16 Font
                {
                    szNull[0] = 0x01;
                    szNull[1] = 0x20;
                } else
                    szNull[0] = SPACE;
                /* remove previous prompts so not scrolled after error */
                vdDisplayAt(obDisp.inHomeCol, (inAmtInputLine - 1), szNull, CLR_EOL);
                vdDisplayAt(obDisp.inHomeCol, inAmtInputLine, szNull, CLR_EOL);
                vdDisplayAt(obDisp.inHomeCol, obDisp.inCharsPerColumn, szNull, CLR_EOL);
            }
            vdSGErrorMessage(0L);   /* Do not want to display this again */
            if (inGGCode() != PHONE) {
                vdGetMessageFromFile(SWIPE_MSG, szCPACMessage);
                vdDisplayAt(1, 3, szCPACMessage, CLR_EOL);
            }
            vdGetMessageFromFile(CPAC_PAN_MESSAGE, szCPACMessage);
            vdDisplayAt(1, 5, szCPACMessage, CLR_EOL);
        }   // if you have error message active
        /* Clear Track Data on bad reads */
        memset(pobTran->srBRec.stT1Data, 0, TRACK1_SIZE);/* Clear Track 1  */
        memset(pobTran->srBRec.stT2Data, 0, TRACK2_SIZE);/* Clear Track 2  */
        strcpy(pobTran->srBRec.szCHolder, szNull);
    }
#endif //IMAM_REMOVE
    return (VS_SUCCESS);
}


/*---------------------------------------------------------------------------
    Function     : inGetCPACAdjustAmount
    Description  : get the new amount for CPAC adjusts.
    Returns      : VS_ERR, VS_SUCCESS or VS_ESCAPE
---------------------------------------------------------------------------*/

int inGetCPACAdjustAmount(TRANSACTION_OBJECT* pobTran) {
    char szAmount[AMT_SIZE + 1];
    signed int inResult,
    inAllow;
    char szAmt[AMT_SIZE + 1];
    char szDisplaySymbol[CUR_SYMBOL_SIZE + 1];
    char szDisplayBuffer[DISP_STR_LEN + 1];
    long lnBaseAmt;
    //unsigned long ulTimerCount; CPAC_LINT_REMOVED
    int inAmtInputLine,
    inMlLen;

    if (getgrid() == 0)
        inAmtInputLine = 3;
    //  (Saritha_b1......moving out TLFB switch )
    /* #ifdef TLFB
        inAmtInputLine = 3;
    #else
            inAmtInputLine = 3;
    #endif  */  /* TLFB */      //(Saritha_b1......moving out TLFB switch )
    else
        inAmtInputLine = 7;

    memset(szDisplayBuffer, '\0', sizeof(szDisplayBuffer));
    szAmount[0] = '\0';

    strcpy(szDisplaySymbol, szGetCurSymbol());
    pobTran->inTransactionCode = ADJUST; //1.41 G Adjust of Offline fix

    /* save old amount */
    pobTran->srBRec.lnOldTotalTransactionAmount = pobTran->srBKey.lnTotalOfTransactionAmount;
    pobTran->srBRec.lnOldTipAmount = pobTran->srBRec.lnTipAmount;  /*kc1*/
    lnBaseAmt = (pobTran->srBKey.lnTotalOfTransactionAmount - pobTran->srBRec.lnTaxAmount - pobTran->srBRec.lnTipAmount - pobTran->srBRec.lnCashBackAmount);

    sprintf(szAmt, SUBSTITUTE_LD, lnBaseAmt);
    vdFormatAmount(szAmt, VS_TRUE);

    vdGetMessageFromFile(SHOW_AMOUNT_MSG, szDisplayBuffer);

    if (getgrid() == 0) {
        inMlLen = strlen(szDisplayBuffer);
        szDisplayBuffer[inMlLen] = 0x01;
        szDisplayBuffer[inMlLen + 1] = 0x20;
        szDisplayBuffer[inMlLen + 1 + 1] = 0x00;
    } else
        strcat(szDisplayBuffer, " ");

    if (getgrid() == 0) {
        /* #ifdef TLFB    (Saritha_b1......moving out TLFB switch )
            vdDisplayAt(obDisp.inHomeCol, 2, szDisplayBuffer, CLR_EOL);
            vdDisplayDataStr(szAmt, 4, NO_CLEAR, ML_RIGHT);
        #else */
        vdDisplayAt(obDisp.inHomeCol, 3, szDisplayBuffer, CLR_EOL);
        vdDisplayDataStr(szAmt, 6, NO_CLEAR, ML_RIGHT);
        //#endif    (Saritha_b1......moving out TLFB switch )
    } else {
        vdDisplayAt(obDisp.inHomeCol, 5, szDisplayBuffer, CLR_EOL);
        vdDispStrAtRight(szAmt, 5, NO_CLEAR);
    }


    //  vdGetMessageFromFile( NEWAMT_MSG, szDisplayBuffer);
    vdGetMessageFromFile(NEWVAL_MSG15, szDisplayBuffer);
    vdDisplayAt(obDisp.inHomeCol, inAmtInputLine, szDisplayBuffer, CLR_EOL);

    //    if ((inResult = inGetAmount(szAmount, VS_TRUE, 1L, 999999999L, szDisplaySymbol)) != VS_SUCCESS)

    if ((pobTran->inOperationCode == BATCH_REVIEW_OPERATION) || (pobTran->inTransactionCode == ADJUST)) {
        if ((inResult = inAdjCustGetAmount(szAmount, 1L, 999999999L, szDisplaySymbol, NEWVAL_MSG15, pobTran)) != VS_SUCCESS)
            return(inResult);
    } else {
        if ((inResult = inCustGetAmount(szAmount, 1L, 999999999L, szDisplaySymbol, NEWVAL_MSG15)) != VS_SUCCESS)
            return(inResult);
    }
    pobTran->srBRec.lnBaseTransactionAmount = atol(szAmount);

    if (fGetTaxProc() == VS_TRUE) {
        if (lnGetTaxPercent() > 0) {
            pobTran->fTaxAdjust = VS_TRUE;
            pobTran->lnOldTaxAmount = pobTran->srBRec.lnTaxAmount;
            inComputePercent(lnGetTaxPercent(), szAmount, pobTran->srBRec.lnBaseTransactionAmount, TAX_FORMAT); /* BB1 DFW#121 01/20/98 */
            pobTran->srBRec.lnTaxAmount = atol(szAmount);
        }
    }

    if (inGetTipPercent() > 0 && pobTran->srBRec.inCode != PHONE && (inGetTipProcessing() > TIP_OFF)) /* bb1 */ {
        if ((inResult = obDisp.inDO_ChooseOne((char *) NULL_CH, pchGetMsg(ASK_AUTO_UPDATE_TIP_MSG15), pchGetMsg(YESNO_MSG5x), 2, NULL_PFI)) == KEY_YES) // CPAC_LINT added char *
        {
            inComputePercent((long) inGetTipPercent(), szAmount, pobTran->srBRec.lnBaseTransactionAmount, TIP_FORMAT);
            pobTran->srBRec.lnTipAmount = atol(szAmount);
            pobTran->fTipAdjust = VS_TRUE; /* bb1 */
        } else {
            pobTran->srBRec.lnTipAmount = pobTran->srBRec.lnOldTipAmount;
            //originally pobTran->fTipAdjust = VS_TRUE;
            pobTran->fTipAdjust = VS_FALSE;
        }
    }

    pobTran->srBKey.lnTotalOfTransactionAmount = pobTran->srBRec.lnBaseTransactionAmount + pobTran->srBRec.lnTipAmount + pobTran->srBRec.lnTaxAmount + pobTran->srBRec.lnCashBackAmount;

    inAllow = inCPACTotTransAmtAlwd(pobTran);
    if (inAllow != VS_SUCCESS) {
        pobTran->srBKey.lnTotalOfTransactionAmount = pobTran->srBRec.lnOldTotalTransactionAmount;   //BugFix SR326
        pobTran->srBRec.lnTipAmount = pobTran->srBRec.lnOldTipAmount;
        return (VS_ERR);
    }
    return (VS_SUCCESS);
}
/*********************************************************************************************
* @func int | inCPACTipAdjust |
*
*       The tip amount is adjusted specially for CPAC.. formatting and giving cur.symbol
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |  	VS_SUCCESS
* 					VS_ESCAPE
* 					VS_ERR
* @end
**********************************************************************************************/

int inCPACTipAdjust(TRANSACTION_OBJECT *pobTran)
{
    char szAmount[AMT_SIZE + 1];
	#ifdef ICICI
		char szTempAmt[AMT_SIZE + 1];
	#endif /* ICICI  */
    char szDisplaySymbol[CUR_SYMBOL_SIZE + 1];
    char szDisplayBuffer[DISP_STR_LEN + 1];
    long lnBaseAmt, lnOldTipAmt;
    //unsigned long ulTimer;   CPAC_LINT_REMOVED
    int inResult, inAmtInputLine, inAllow;
    int inGrid, inCol;  // CPAC_ML

	  inGrid=getgrid();

	  if (inGrid == 0)
	  	inAmtInputLine = 3;

/* #ifdef TLFB		//(Saritha_b1......moving out TLFB switch )
         inAmtInputLine = 3;
#else
	  inAmtInputLine = 3;
#endif */ 		//(Saritha_b1......moving out TLFB switch )
	  else inAmtInputLine = 7;

	  szAmount[0] = '\0';
	  memset(szDisplayBuffer,0,sizeof(szDisplayBuffer));

	  strcpy (szDisplaySymbol,szGetCurSymbol());
	  pobTran->inTransactionCode=TIP_ADJUST;
      /* pj1 save old amount first */
      pobTran->srBRec.lnOldTotalTransactionAmount = pobTran->srBKey.lnTotalOfTransactionAmount;
      pobTran->srBRec.lnOldTipAmount = pobTran->srBRec.lnTipAmount;

      /* Display old tip amount */
      sprintf(szAmount,SUBSTITUTE_LD, pobTran->srBRec.lnTipAmount);
      //vdPutDecPoint(szAmount);
	  vdFormatAmount(szAmount, VS_TRUE);					//leo_apr11 Added
      vdGetMessageFromFile( TIP_AMOUNT_MSG,szDisplayBuffer);

      if (inGrid == 0) {    // CPAC_ML
         obDisp.inDetailLine = 2;
         vdDisplayAt(obDisp.inHomeCol, obDisp.inDetailLine, szDisplayBuffer, CLR_EOL);
         inCol=21-strlen(szAmount)+1;
         inMLDisplayAt (inCol, 4, szAmount, NO_CLEAR,
                        ML_USE_GIVEN_FONT, ML_ACTION_FONT, "F:ASC8X21.VFT");
      }
      else {
         obDisp.inDetailLine = 5;
         vdDisplayAt(obDisp.inHomeCol, obDisp.inDetailLine, szDisplayBuffer, CLR_EOL);
         vdDispStrAtRight( szAmount, obDisp.inDetailLine, NO_CLEAR );
      }

      /* Prompt for new tip amount */
      szAmount[0] = '\0';
      vdGetMessageFromFile( NEW_TIP_AMT_MSG,szDisplayBuffer);

      vdGetMessageFromFile( O3200_NEW_TIP_AMT_MSG,szDisplayBuffer);
      vdDisplayAt(obDisp.inHomeCol, inAmtInputLine, szDisplayBuffer, CLR_EOL);


      //inResult = inGetAmount(szAmount, VS_TRUE, 0L, 999999999L, szDisplaySymbol);
   //    inResult = inCustGetAmount(szAmount, 0L, 999999999L, szDisplaySymbol, O3200_NEW_TIP_AMT_MSG);
#ifdef TIP_MAX_LIMIT_DEFINED
				if ( (inResult = inCustGetAmount(szAmount, 0L,
                            pobTran->srBRec.lnBaseTransactionAmount,
                            szDisplaySymbol, O3200_NEW_TIP_AMT_MSG)) != VS_SUCCESS )
#else
				if ( (inResult = inCustGetAmount(szAmount, 0L,
                            999999999L, szDisplaySymbol, O3200_NEW_TIP_AMT_MSG)) != VS_SUCCESS )
#endif
				{
					memset (pobTran->szRespMsg, 0, RESP_MSG_SIZE); //Bug fix .. when txn not allowed donot show
					return(VS_ERR);
				}
	#ifdef ICICI
    		if(atol(szAmount) <=0)
    		{
    	  		vdDisplayMessageFromFile( ZERO_ENTRY_NOT_ALLOWED_MSG21/*CPAC_INVALID_TIP_MSG*/, WARNING_MSG);
			inResult = -1;
			return(inResult);
    		}
    		inComputePercent((long )inGetTipPercent(),szTempAmt,pobTran->srBRec.lnBaseTransactionAmount,TIP_FORMAT);
		if(inGetTipPercent()>0)
              {
              	if(atol(szTempAmt)<atol(szAmount))
                     {
                     	vdDisplayMessageFromFile( OUT_OF_RANGE_ERR_MSG/*CPAC_INVALID_TIP_MSG*/, WARNING_MSG);
				inResult = -1;
				return(inResult);							   // approved...
			}
		}
	#endif /* ICICI */

      	if (inResult >=0 )
      	{
       	lnBaseAmt = (pobTran->srBKey.lnTotalOfTransactionAmount - pobTran->srBRec.lnTaxAmount -pobTran->srBRec.lnTipAmount);
		#ifndef CITI_PHIL
			if(atol(szAmount)>= lnBaseAmt)
			{
				vdDisplayMessageFromFile( OUT_OF_RANGE_ERR_MSG/*CPAC_INVALID_TIP_MSG*/, WARNING_MSG);
				inResult = -1;
				memset (pobTran->szRespMsg, 0, RESP_MSG_SIZE); //Bug fix .. when txn not allowed donot show
				return(inResult);							   // approved...
			}								//Bug_fix for not allowing more tip than base...
		#endif /* CITI_PHIL_citiphil_28feb_don_DSC_1.4 No limit for Tip adjust */

		lnOldTipAmt = pobTran->srBRec.lnTipAmount;
		pobTran->srBRec.lnTipAmount = atol(szAmount);

		inAllow = inCPACTotTransAmtAlwd(pobTran);
		if (inAllow != VS_SUCCESS)
		{
			pobTran->srBRec.lnTipAmount = lnOldTipAmt;
			return (VS_ERR);
		}

		pobTran->srBKey.lnTotalOfTransactionAmount = lnBaseAmt + pobTran->srBRec.lnTipAmount +
                                                                   pobTran->srBRec.lnTaxAmount;

      	}

	return (inResult);

}

/*-------------------------------------------------------------------------
    Function :  inCPACBatchTotalsOperation()
    Description : Displays the cuurrent batch totals for a particular host
    Parameters :
    Returns : VS_SUCCESS, VS_ERR
    Globals :
    Notes :
    Modification History :

--------------------------------------------------------------------------*/

int inCPACBatchTotalsOperation(TRANSACTION_OBJECT* pobTran) {
    //int inChar;   CPAC_LINT_REMOVED
    double dbSalesTotal, dbRefundsTotal;
	unsigned long lnSalesCount, lnRefundsCount;
    char szSalesAmt[AMT_SIZE + 1];
    char szRefundsAmt[AMT_SIZE + 1];
    char szTotalAmt[AMT_SIZE + 1];
	char buff[21];
    ACCUM_REC srHostTotals;

    /*    if (inGetCheckMID(pobTran) == VS_SUCCESS)    select merchant */
    /*    { */
    /* Saritha_b1.....Start....Host selection is moved........*/
    //#ifndef TLFB
    // if (inGetHostNum(pobTran) == VS_SUCCESS)   /* select host */
    //  {
    //#else
    //if (inTLFBGetHostNum(pobTran) == VS_SUCCESS)   /* select host */
    //{
    //#endif /* ifndef else TLFB */

    /* Saritha_b1.....End....Host selection is moved........*/


    if (inGetHostTotals(pobTran, &srHostTotals  /*, inGetHostHandle()*/) != VS_SUCCESS)
        return (VS_ERR);

    if (inGetHostTranCnt(pobTran) == 0) {
        vdSGErrorMessage(BATCH_EMPTY_MSG);
        return (VS_ERR);
    }

    dbSalesTotal = srHostTotals.srTotals[CREDIT_CARD].dbAmount[DEBIT_TRAN] + srHostTotals.srTotals[DEBIT_CARD].dbAmount[DEBIT_TRAN];
    dbRefundsTotal = srHostTotals.srTotals[CREDIT_CARD].dbAmount[CREDIT_TRAN] + srHostTotals.srTotals[DEBIT_CARD].dbAmount[CREDIT_TRAN];
	lnSalesCount = srHostTotals.srTotals[CREDIT_CARD].lnCount[DEBIT_TRAN] + srHostTotals.srTotals[DEBIT_CARD].lnCount[DEBIT_TRAN];  //
	lnRefundsCount = srHostTotals.srTotals[CREDIT_CARD].lnCount[CREDIT_TRAN] + srHostTotals.srTotals[DEBIT_CARD].lnCount[CREDIT_TRAN];  //
    szSalesAmt[0] = '\0';

    vdDb2Str(dbSalesTotal, szSalesAmt);
    // sprintf(szSalesAmt, SUBSTITUTE_LD, lnSalesTotal);
    szRefundsAmt[0] = '\0';
    vdDb2Str(dbRefundsTotal, szRefundsAmt);
    //sprintf(szRefundsAmt, SUBSTITUTE_LD, lnRefundsTotal);
    szTotalAmt[0] = '\0';
    vdDb2Str(dbSalesTotal - dbRefundsTotal, szTotalAmt);
    // sprintf(szTotalAmt, SUBSTITUTE_LD, lnSalesTotal - lnRefundsTotal);

	memset(buff, 0x00, sizeof(buff));                //LIEM ADD AND CHANGE
	sprintf(buff, "Sales:[%03ldx]", lnSalesCount);
	vdDisplayAt(1, 3, buff, CLR_EOL);
    vdDispFormattedAmt(szSalesAmt, SALES_AMT_MSG, 4);  
	memset(buff, 0x00, sizeof(buff));
	sprintf(buff, "Rfnds:[%03ldx]", lnRefundsCount);
	vdDisplayAt(1, 5, buff, CLR_EOL);
    vdDispFormattedAmt(szRefundsAmt, REFUNDS_AMT_MSG, 6);
    //vdDispFormattedAmt( szTotalAmt, TOTALAMT_MSG9, obDisp.inStatusLine );

    //vdDelay(PROMPT_DELAY);
    //vdDelay(PROMPT_DELAY);

    if (getgrid() == 0) {
        gotoxy(1, 2);
        delline();
        vdDispFormattedAmt(szTotalAmt, TOTALAMT_MSG9, 4);
    } else {
        //gotoxy(1, 3);
        //delline();
        //delline();  no need to scroll 2 line
        vdDispFormattedAmt(szTotalAmt, TOTALAMT_MSG9, 8);
    }
    if ((dbSalesTotal - dbRefundsTotal) < -999999999L)
        vdDisplayAt(10, 8, "-", NO_CLEAR);

    inWaitKey(inGetIdleTimeOut());
    // }  /* Saritha_b1.........Host selection is moved........*/
    //else return (VS_ERR); /* Saritha_b1.....Start....Host selection is moved........*/
    /*    }
        else return (VS_ERR); */

    return(VS_SUCCESS);
}

/*-------------------------------------------------------------------------
    Function :  inCPACVoidYesNo()
    Description :
    Parameters :
    Returns : VS_SUCCESS, VS_ERR
    Globals :
    Notes :
    Modification History :

--------------------------------------------------------------------------*/

int inCPACVoidYesNo(TRANSACTION_OBJECT* pobTran) {
    int inFontType = 1,
    inGrid;
    char szDisplayBuffer[DISP_STR_LEN + MESSAGE_SIZE + 1],
    szPAN[PAN_SIZE + 1];
    signed char chAnswer;
    char szMessage[MESSAGE_SIZE + 1],
    szAmt[AMT_SIZE + 1],
    szLocBuf[2 + 1];
    char szPAN_Part1[PAN_SIZE / 2 + 2]; //include the space for "-" at the end of Part1 of PAN
    char szPAN_Part2[PAN_SIZE / 2 + 1];
    memset(szPAN, 0, sizeof(szPAN));
    memset(szDisplayBuffer, 0, sizeof(szDisplayBuffer));

    sprintf(szAmt, SUBSTITUTE_LD, pobTran->srBKey.lnTotalOfTransactionAmount);

    vdGetMessageFromFile(CPAC_SHOW_AMOUNT_MSG, szDisplayBuffer);
    strcpy(szPAN, pobTran->srBRec.szPAN);

    //  LENIN ATL   vdPutDecPoint(szAmt);
    vdFormatAmount(szAmt, VS_FALSE);
    inFontType = get_font_mode();
    inGrid = getgrid();

    if (inFontType == 2) {
        // 2 byte addresssing scheme
        memset(szLocBuf, 0x00, sizeof(szLocBuf));
        szLocBuf[0] = 0x01;
        szLocBuf[1] = 0x20;
        strcat(szDisplayBuffer, szLocBuf);
        // szAmt has the amount already formatted
    } else {
        // Normal messages (1 byte addressing)
        strcpy(szLocBuf, " ");
        strcat(szDisplayBuffer, szLocBuf);
        strcat(szDisplayBuffer, szAmt);
        strcat(szDisplayBuffer, szLocBuf);
    }

    vdGetMessageFromFile(CPAC_VOID_ORNOT_MSG, szMessage);

    if (inGrid == 0)  //16 0r 8 chars
    {
        /*
                inMLDisplayAt (obDisp.inHomeCol, 3, szPAN, NO_CLEAR,
                    ML_USE_GIVEN_FONT, ML_ACTION_FONT, "ASC8X21.VFT");
                */
        memset(szDisplayBuffer, 0x00, sizeof(szDisplayBuffer));
        vdCPACGetMessageFromReceiptFile(CPAC_SHOW_AMOUNT_MSG, szDisplayBuffer, pobTran);
        memset(szPAN_Part1, NULL_CH, sizeof(szPAN_Part1));
        strncpy(szPAN_Part1, szPAN, (PAN_SIZE / 2 - 1));
        strcat(szPAN_Part1, "-");
        memset(szPAN_Part2, NULL_CH, sizeof(szPAN_Part2));
        strncpy(szPAN_Part2, szPAN + (PAN_SIZE / 2 - 1), (PAN_SIZE / 2));
        inMLDisplayAt(obDisp.inHomeCol, 3, szPAN_Part1, NO_CLEAR, ML_USE_GIVEN_FONT, ML_ACTION_FONT, "F:ASC8X21.VFT");
        inMLDisplayAt(obDisp.inHomeCol, 4, szPAN_Part2, NO_CLEAR, ML_USE_GIVEN_FONT, ML_ACTION_FONT, "F:ASC8X21.VFT");
        inMLDisplayAt(obDisp.inHomeCol, 5, szDisplayBuffer, CLR_EOL, ML_USE_GIVEN_FONT, ML_ACTION_FONT, "F:ASC8X21.VFT");



        //  inMLDisplayAt (obDisp.inHomeCol, 3, szPAN, NO_CLEAR,
        //      ML_USE_GIVEN_FONT, ML_ACTION_FONT, "F:ASC8X21.VFT");
        //strcat (szDisplayBuffer , szAmt);
        //vdDisplayAt(obDisp.inHomeCol, 3, szDisplayBuffer, NO_CLEAR);

        /*
                inMLDisplayAt (obDisp.in3200BarCol * 2 - 1 - strlen(szAmt), 6, szAmt, NO_CLEAR,
                    ML_USE_GIVEN_FONT, ML_ACTION_FONT, "ASC8X21.VFT");
                */
        //inMLDisplayAt (obDisp.inHomeCol ,  5, "            ", NO_CLEAR,
        //  ML_USE_GIVEN_FONT, ML_ACTION_FONT, "F:ASC8X21.VFT");
        inMLDisplayAt(obDisp.inHomeCol, 6, szAmt, NO_CLEAR, ML_USE_GIVEN_FONT, ML_ACTION_FONT, "F:ASC8X21.VFT");

        /* inMLDisplayAt (obDisp.in3200BarCol * 2 - 1 - strlen(szAmt), 6, szAmt, NO_CLEAR,
                    ML_USE_GIVEN_FONT, ML_ACTION_FONT, "F:ASC8X21.VFT"); */

        vdDisplayAt(1, 4, szMessage, CLR_EOL);
    } else {
        vdDisplayAt(obDisp.inHomeCol, 3, szPAN, NO_CLEAR);
        vdDisplayAt(obDisp.inHomeCol, 5, szDisplayBuffer, NO_CLEAR);
        vdDisplayAt(1, 7, szMessage, CLR_EOL);
    }

    chAnswer = (char) obDisp.inDO_ChooseOne(NULL, NULL, (char *) pchGetMsg(YESNO_MSG5x), 2, NULL_PFI);

    if (chAnswer == KEY_YES) {
        pobTran->inTransactionCode = VOID;  //1.41 version I fix offline - review void
        return(VS_SUCCESS);
    } else if (chAnswer == KEY_NO)
        return (VS_ERR);
    return (VS_ERR);
    //return (VS_SUCCESS);  // CPAC_LINT added
}


/*---------------------------------------------------------------------------
    Function :    inCPACGetInvNum()
    Description : This function obtains the invoice number from the user if
                  the key invoice flag is on.
    Parameters :
    Returns :     VS_ERR or VS_SUCCESS
    Notes :
 ---------------------------------------------------------------------------*/

int inCPACGetInvNum(TRANSACTION_OBJECT* pobTran) {
#ifndef IMAM_REMOVE
    char szInvoiceNumber[INV_NUM_SIZE + 1];
    int inResult;

    int inRowLim = inGetRowLim();

    inResult = VS_ERR;


#if CPAC_REMOVED

    if (fGetKeyInvNum() == VS_FALSE)
        return(VS_SUCCESS);

#endif /* CPAC_REMOVED */
    /*
    #ifdef CITI_IND
        inResult = inCheckForDuplicate(pobTran);
        if (inResult == VS_SUCCESS) return (VS_ERR);
    #endif*/

    if (fGetKeyInvNum() == VS_FALSE) {
        /*
         *      if the transaction is a Close Tab and Offline (which means the card
         *      number is the same as the Open Tab) then use the invoice number in the batch record
         */
        if (!pobTran->srBRec.fCloseTabSameCard)
            pobTran->srBKey.lnInvNum = lnGetInvNum();
        return(VS_SUCCESS);
    }


    /* If the transaction is Close Tab and card number is the same as the
     * Open Tab, exit.
     * Else if the card number is different (it was changed to online) there
     * needs to be a new invoice number.
     */
    if (pobTran->srBRec.fCloseTabSameCard)
        return(VS_SUCCESS);

    while (TRUE) {
        if (inResult == VS_SUCCESS) {
            vdDisplayMessageFromFile(DUPLICATE_INV_NUM_MSG, STATUS_MSG);
            SVC_WAIT(2000);
        }
        szInvoiceNumber[0] = '\0';

#if VIP_RMD
        inResult = inEnterWithMessage(INVOICE_MSG, SCROLL_DISPLAY_TRUE, szInvoiceNumber, INPUT_NUMS, inGetInvNumSize(), inValidateString);
#endif /* VIP_RMD */

        if (getgrid() == 0)
            inResult = inCPACEnterWithMessage(INVOICE_MSG, SCROLL_DISPLAY_TRUE, 3, 6, szInvoiceNumber, INPUT_NUMS, inGetInvNumSize(), inValidateString);
        else
            inResult = inCPACEnterWithMessage(INVOICE_MSG, SCROLL_DISPLAY_TRUE, 5, 5, szInvoiceNumber, INPUT_NUMS, inGetInvNumSize(), inValidateString);


        window(obDisp.inHomeCol, obDisp.inTitleLine, inRowLim, obDisp.inCharsPerColumn);

        if (gu_clr_state())
            return(VS_ESCAPE);

        if (inResult < 0) {
            vdSGErrorMessage(TXN_CANCELLED);
            return (inResult);
        }

        if (atol(szInvoiceNumber) == 0L) {
            vdDisplayMessageFromFile(INVALID_INV_NUM_ERR_MSG, STATUS_MSG);
            SVC_WAIT(2000);
            inResult = VS_ERR;
            continue;
        }

        /* Search in the Open Tab Batch for same Invoice Number and Host Type */
        /* Search in the Host Batch for same Invoice Number */
        pobTran->srBKey.lnInvNum = atol(szInvoiceNumber);

        //#ifndef CITI_IND
#ifdef BATCH_DEFINED
        inResult = inCheckForDuplicate(pobTran);
#endif // BATCH_DEFINED
        //#endif

        if (inResult != VS_SUCCESS)
            break;
    }

    vdSetInvNum(pobTran->srBKey.lnInvNum);

    vdSGErrorMessage(0L);
#endif //IMAM_REMOVE
    return(VS_SUCCESS);
}

/*-------------------------------------------------------------------------
    Function    : inCPACGetInvoiceNumber
    Description : This function checks if there is transaction record
                  corresponding to an invoice number exists in the Batch.
                  Called in the VOID/ADJUST transaction flow.
    Parameters :
    Returns :
    Notes :
--------------------------------------------------------------------------*/

int inCPACGetInvoiceNumber(TRANSACTION_OBJECT* pobTran) {
    char szInvoiceNumber[INV_NUM_SIZE + 1];
    int inResult;
    int inRowLim = inGetRowLim();


    if (getgrid() == 0)
        inResult = inCPACEnterWithMessage(INVOICE_MSG, SCROLL_DISPLAY_FALSE, 3, 6, szInvoiceNumber, INPUT_NUMS, inGetInvNumSize(), inValInvoiceEntry);
    else
        inResult = inCPACEnterWithMessage(INVOICE_MSG, SCROLL_DISPLAY_FALSE, 5, 5, szInvoiceNumber, INPUT_NUMS, inGetInvNumSize(), inValInvoiceEntry);

    window(obDisp.inHomeCol, obDisp.inTitleLine, inRowLim, obDisp.inCharsPerColumn);

    if (inResult == VS_ESCAPE)
        return (VS_ESCAPE);

    if (inResult < 0)
        return (VS_ERR);

    pobTran->srBKey.lnInvNum = atol(szInvoiceNumber);

    return (VS_SUCCESS);
}

/*---------------------------------------------------------------------------
    Function     : inGetCPACCloseTabAmount
    Description  : get the new amount for close tab.
    Returns      : VS_ERR, VS_SUCCESS or VS_ESCAPE
 ---------------------------------------------------------------------------*/

int inGetCPACCloseTabAmount(TRANSACTION_OBJECT* pobTran) {
    char szAmount[AMT_SIZE + 1];
    int inResult,
    inAmtInputLine;
    char szAmt[AMT_SIZE + 1];
    char szDisplaySymbol[CUR_SYMBOL_SIZE + 1];
    char szDisplayBuffer[DISP_STR_LEN + 1];
    long lnBaseAmt;
    int inGrid,
    inCol;  // CPAC_ML
    //unsigned long ulTimerCount;  CPAC_LINT_REMOVED

    inGrid = getgrid();

    if (inGrid == 0)
        inAmtInputLine = 3;  // CPAC_ML
    else
        inAmtInputLine = 7;

    memset(szDisplayBuffer, '\0', sizeof(szDisplayBuffer));
    szAmount[0] = '\0';

    strcpy(szDisplaySymbol, szGetCurSymbol());

    /* save old amount */
    pobTran->srBRec.lnOldTotalTransactionAmount = pobTran->srBKey.lnTotalOfTransactionAmount;
    pobTran->srBRec.lnOldTipAmount = pobTran->srBRec.lnTipAmount;  /*kc1*/
    lnBaseAmt = (pobTran->srBKey.lnTotalOfTransactionAmount - pobTran->srBRec.lnTaxAmount - pobTran->srBRec.lnTipAmount - pobTran->srBRec.lnCashBackAmount);

    sprintf(szAmt, SUBSTITUTE_LD, lnBaseAmt); /* mb1 */
    //vdPutDecPoint(szAmt);
    vdFormatAmount(szAmt, VS_TRUE);

    vdGetMessageFromFile(SHOW_AMOUNT_MSG, szDisplayBuffer);

    strcat(szDisplayBuffer, " ");

    if (inGrid == 0) {
        // CPAC_ML
        obDisp.inDetailLine = 2;
        vdDisplayAt(obDisp.inHomeCol, obDisp.inDetailLine, szDisplayBuffer, CLR_EOL);
        inCol = 21 - strlen(szAmt) + 1;
        inMLDisplayAt(inCol, 4, szAmt, NO_CLEAR, ML_USE_GIVEN_FONT, ML_ACTION_FONT, "F:ASC8X21.VFT");
    } else {
        obDisp.inDetailLine = 5;
        vdDisplayAt(obDisp.inHomeCol, obDisp.inDetailLine, szDisplayBuffer, CLR_EOL);
        vdDispStrAtRight(szAmt, obDisp.inDetailLine, NO_CLEAR);
    }

    vdGetMessageFromFile(NEWVAL_MSG15, szDisplayBuffer);
    vdDisplayAt(obDisp.inHomeCol, inAmtInputLine, szDisplayBuffer, CLR_EOL);

    //    if ((inResult = inGetAmount(szAmount, VS_TRUE, 1L, 999999999L, szDisplaySymbol)) != VS_SUCCESS)
#ifdef PCOMP_MAX_LIMIT_DEFINED
    if ((inResult = inCustGetAmount(szAmount, 1L, lnBaseAmt, szDisplaySymbol, NEWVAL_MSG15)) != VS_SUCCESS)
    #else
        if ((inResult = inCustGetAmount(szAmount, 1L, 999999999L, szDisplaySymbol, NEWVAL_MSG15)) != VS_SUCCESS)
        #endif
            return(inResult);

    pobTran->srBRec.lnBaseTransactionAmount = atol(szAmount);

    return (VS_SUCCESS);
}

/*********************************************************************************************
* @func int | inCPACDefaultDisplayReviewRec |
*
*       Displays Transaction information during batch review processes.
*
*           NOTE: This function may be overloaded using Field ID: DISPLAY_REVIEW_REC.
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |  VS_SUCCESS
* @end
**********************************************************************************************/

int inCPACDefaultDisplayReviewRec(TRANSACTION_OBJECT* pobTran) {
    char szAmt[AMT_SIZE + 1];
    char szCardLabel[CLABEL_SIZE + 1];
    char szTransType[MESSAGE_SIZE + 1];
    char szTransPrefix[MESSAGE_SIZE + 1];
    char szCentPrefix[21 + 1];
    //char szLocBuf [2 + 1];  cpac_2.2a
    //unsigned long ulTimerCount;  CPAC_LINT_REMOVED
    char szDisplayBuffer[DISP_STR_LEN + MESSAGE_SIZE + 1]; /* added trans. type */
    char szPAN[PAN_SIZE + 1];
    char szPAN_Part1[PAN_SIZE / 2 + 2]; //include the space for "-" at the end of Part1 of PAN
    char szPAN_Part2[PAN_SIZE / 2 + 1];
    int inFontType = 1,
    inGrid, /*inTime,*/ inFLen,
    inSLen;  // (1 -> 1 byte address 2 -> 2 byte address )

   //spqa to display the invoice number when voiding jrd
   char szInvoice[12 + 1];
   long lnInvNum;
   lnInvNum = pobTran->srBKey.lnInvNum;
   memset(szInvoice, 0, sizeof(szInvoice));
   sprintf(szInvoice, "Inv #: %ld", lnInvNum);


    /* #ifdef TLFB  //(Saritha_b1......moving out TLFB switch )
        char szThaiMessage[MESSAGE_SIZE+1];     //Saritha_b1 commented as this variable is not been used.
    #endif  */ /* TLFB */

    memset(szCardLabel, 0, sizeof(szCardLabel));
    memset(szPAN, 0, sizeof(szPAN));
    memset(szTransType, 0, sizeof(szTransType));
    memset(szDisplayBuffer, 0, sizeof(szDisplayBuffer));


    sprintf(szAmt, SUBSTITUTE_LD, pobTran->srBKey.lnTotalOfTransactionAmount);

    /* 1.4 change added load cst */
    if (inLoadCSTRec(pobTran->srBKey.inCurrencyIndex) != VS_SUCCESS) {
        vdDisplayMessageFromFile(CST_ERR_MSG, WARNING_MSG);
        return(VS_ERR);
    }
    // strcpy (szDisplayBuffer,szGetCurSymbol());

    strcpy(szPAN, pobTran->srBRec.szPAN);

    // LENIN ATL    vdPutDecPoint(szAmt);
    vdFormatAmount(szAmt, VS_TRUE);
    vdGetMessageFromFile(pobTran->srBRec.lnMessage, szTransType);
    //#if 0
    inFontType = get_font_mode();
#if 0
    if (inFontType == 2)  // 2 byte addresssing scheme
    {
        strcpy(szLocBuf, " ");
        strcat(szDisplayBuffer, szLocBuf);
        strcat(szDisplayBuffer, szAmt);
    }
    else { // Normal messages (1 byte addressing)
        strcpy(szLocBuf, "  ");
        strcat(szDisplayBuffer, szLocBuf);
        strcat(szDisplayBuffer, szAmt);
        strcat(szDisplayBuffer, szLocBuf);
    }
    #endif /* 0 */
    strcpy(szDisplayBuffer, szAmt);
    memset(szTransPrefix, '\0', sizeof(szTransPrefix));
    if (pobTran->srBKey.fVoided == VS_TRUE)
        vdGetMessageFromFile(VOID_MSG6, szTransPrefix);
    else if (pobTran->srBRec.inNumberOfAdjusts > 0)
        vdGetMessageFromFile(ADJUST_MSG6, szTransPrefix);
    else if (pobTran->srBRec.inNumberOfTipAdjusts > 0)
        vdGetMessageFromFile(CPAC_TIP_RVW_ADJUST_MSG, szTransPrefix);
    szCardLabel[CLABEL_SIZE] = NULL_CH;

    if (pobTran->srBRec.inTranCardType == DEBIT_CARD)
        vdGetMessageFromFile(DEBIT_MSG, szCardLabel);
    else
        strcpy(szCardLabel, szGetCardLabel());
    //vdGetCardLabel(szCardLabel);

    memset(szCentPrefix, NULL_CH, sizeof(szCentPrefix));
    vdClearNonTitleLines();

    if ((shGetTransactionCode(pobTran) == VOID) && (pobTran->inOperationCode != BATCH_REVIEW_OPERATION))
        vdDispMsgAt(VOID_TRT_MSG, 1, 1, NO_CLEAR);
    else if ((shGetTransactionCode(pobTran) == CPAC_PHIL_ADJUST) && (pobTran->inOperationCode != BATCH_REVIEW_OPERATION))
        vdDispMsgAt(ADJUST_MSG6, 1, 1, NO_CLEAR);
    else if ((shGetTransactionCode(pobTran) == ADJUST) && (pobTran->inOperationCode != BATCH_REVIEW_OPERATION))
        vdDispMsgAt(ADJUST_MSG6, 1, 1, NO_CLEAR);
    else if (((pobTran->inTransactionCode == TIP_ADJUST) || (pobTran->inTransactionCode == LOAD_TIP_DETAILS)) && (pobTran->inOperationCode != BATCH_REVIEW_OPERATION))
        vdDispMsgAt(ADD_TIP_OFFLINE_MSG, 1, 1, NO_CLEAR);
    else if ((pobTran->inTransactionCode == PRE_COMP) && (pobTran->inOperationCode != BATCH_REVIEW_OPERATION))
        vdDispMsgAt(PRE_COMP_ITEM_MSG15, 1, 1, NO_CLEAR);
    else if ((pobTran->inTransactionCode == OPENTAB_DEL) && (pobTran->inOperationCode != BATCH_REVIEW_OPERATION))
        vdDispMsgAt(OPENTAB_DEL_MSG15, 1, 1, NO_CLEAR);
    else {
        vdDispMsgAt(SUMMARY_REVIEW_TRT_MSG, 1, 1, NO_CLEAR);/*deepika*/
    }


    inGrid = getgrid();

    if (pobTran->srBRec.fManual == VS_TRUE)
        memset(pobTran->srBRec.szCHolder, 0, CHOLDER_SIZE + 1);

    if (inGrid == 0)  //16 0r 8 chars
    {
        /*
            inMLDisplayAt (obDisp.inHomeCol, 3, szCardLabel, NO_CLEAR,
                            ML_USE_GIVEN_FONT, ML_ACTION_FONT, "ASC8X21.VFT");
            inMLDisplayAt (obDisp.inHomeCol, 4, szPAN, NO_CLEAR,
                            ML_USE_GIVEN_FONT, ML_ACTION_FONT, "ASC8X21.VFT");
            vdDisplayAt (obDisp.inHomeCol, 3, szTransType, NO_CLEAR);
            inFLen = strlen(szTransType)/inFontType;
            inSLen = strlen (szTransPrefix)/inFontType;
            if (inSLen > (obDisp.in3200BarCol - inFLen))
                szTransPrefix[((obDisp.in3200BarCol - inFLen) * 2) - 1] = 0X00;
            vdDisplayAt (obDisp.inHomeCol + strlen(szTransType)/inFontType, 3, szTransPrefix, NO_CLEAR);
            vdDisplayAt(obDisp.inHomeCol, 4, szDisplayBuffer, NO_CLEAR);
            inMLDisplayAt (obDisp.in3200BarCol * 2 - 1 - strlen(szAmt), 8, szAmt, NO_CLEAR,
                            ML_USE_GIVEN_FONT, ML_ACTION_FONT, "ASC8X21.VFT");
            */
        //  --- start
        vdDisplayAt(obDisp.inHomeCol, 2, szTransType, NO_CLEAR);
        inFLen = strlen(szTransType) / inFontType;
        inSLen = strlen(szTransPrefix) / inFontType;


#ifndef TLFB
        if (inSLen > (obDisp.in3200BarCol - inFLen))
            szTransPrefix[((obDisp.in3200BarCol - inFLen) * 2) - 1] = 0X00;
        vdDisplayAt(obDisp.inHomeCol + strlen(szTransType) / inFontType, 2, szTransPrefix, NO_CLEAR);
#else
        //  szTransPrefix[((obDisp.in3200BarCol - inFLen) *2 ) - 1] = 0X00;
        // sprintf(szThaiMessage, "%s%s", szTransType, szTransPrefix);
        //bykelvin_f2       inFLen=inFLen/2;
        vdDisplayAt(obDisp.inHomeCol + inFLen, 2, szTransPrefix, NO_CLEAR);
        //inMLDisplayAt (obDisp.inHomeCol + strlen(szTransType) , 2, szTransPrefix, NO_CLEAR, ML_USE_GIVEN_FONT, ML_ACTION_FONT, "F:THAIFNT.VFT");
#endif
        inMLDisplayAt(obDisp.inHomeCol, 5, szCardLabel, NO_CLEAR, ML_USE_GIVEN_FONT, ML_ACTION_FONT, "F:ASC8X21.VFT");
        memset(szPAN_Part1, NULL_CH, sizeof(szPAN_Part1));
        strncpy(szPAN_Part1, szPAN, (PAN_SIZE / 2 - 1));
        strcat(szPAN_Part1, "-");
        memset(szPAN_Part2, NULL_CH, sizeof(szPAN_Part2));
        strncpy(szPAN_Part2, szPAN + (PAN_SIZE / 2 - 1), (PAN_SIZE / 2));
        inMLDisplayAt(obDisp.inHomeCol, 6, szPAN_Part1, NO_CLEAR, ML_USE_GIVEN_FONT, ML_ACTION_FONT, "F:ASC8X21.VFT");
        inMLDisplayAt(obDisp.inHomeCol, 7, szPAN_Part2, NO_CLEAR, ML_USE_GIVEN_FONT, ML_ACTION_FONT, "F:ASC8X21.VFT");
        inMLDisplayAt(obDisp.inHomeCol, 8, szDisplayBuffer, NO_CLEAR, ML_USE_GIVEN_FONT, ML_ACTION_FONT, "F:ASC8X21.VFT");
        //  --- end
    } else {
        if ((pobTran->srBKey.fVoided == VS_TRUE) || (pobTran->srBRec.inNumberOfAdjusts > 0))
            strcat(szTransPrefix, " ");
        strcat(szTransPrefix, szTransType);
        if (strlen(szTransPrefix) > (obDisp.in3200BarCol - 1))
            szTransPrefix[obDisp.in3200BarCol - 1] = 0x00;
     
		vdDisplayAt(obDisp.inHomeCol, 3, szTransPrefix,         NO_CLEAR);
		{ // to display card holder
			char szCardHolder[22];
			memset(szCardHolder, 0x00, sizeof(szCardHolder));
			strncpy(szCardHolder, pobTran->srBRec.szCHolder, 16);
			vdDisplayAt(obDisp.inHomeCol, 4, szCardHolder, NO_CLEAR);
		}
		vdDisplayAt(obDisp.inHomeCol, 5, szPAN,           		NO_CLEAR);
		vdDisplayAt(obDisp.inHomeCol, 6, szDisplayBuffer,       NO_CLEAR);
		{ // Display the Trace /Invoice, thanks to ChunFeng
			memset(szDisplayBuffer, '\0', sizeof(szDisplayBuffer));
			sprintf(szDisplayBuffer, "TRACE#:  %06ld", pobTran->srBKey.lnInvNum);
 		    vdDisplayAt(obDisp.inHomeCol, 7, szDisplayBuffer, NO_CLEAR);
		}
    }
    return (VS_SUCCESS); // CPAC_LINT_ADDED
}

/*---------------------------------------------------------------------------
    Function     : inCPACGetAuthCode
    Description  : Gets the auth code.
    Returns      : VS_ERR, VS_SUCCESS, VS_FAILURE or VS_ESCAPE
---------------------------------------------------------------------------*/
int inCPACGetAuthCode(TRANSACTION_OBJECT* pobTran) {
    char szAuthCode[AUTH_CODE_SIZE + 1];
    char szDisplayBuffer[DISP_STR_LEN + 1];
    int inResult,
    inTemp;
    /* Get Auth Code */
    /*
        if ((inResult = inEnterWithMessage(AUTH_CODE_MSG, SCROLL_DISPLAY_TRUE, szAuthCode, INPUT_ALNUMS,
                                  AUTH_CODE_SIZE, inValidateString)) >= 0)
    */
#ifdef CITI_PHIL
    if (getgrid() == 0)
        inResult = inCPACEnterWithMessage(AUTH_CODE_MSG, SCROLL_DISPLAY_FALSE, 3, 6, szAuthCode, INPUT_ALNUMS, AUTH_CODE_SIZE, inCITIValidateString);
    else
        //inResult = inCPACEnterWithMessage(AUTH_CODE_MSG, SCROLL_DISPLAY_FALSE, inImamLineNumber-1, inImamLineNumber-1, szAuthCode, INPUT_ALNUMS, AUTH_CODE_SIZE, inCITIValidateString);
		inResult = inCPACEnterWithMessage(AUTH_CODE_MSG, SCROLL_DISPLAY_FALSE, inImamLineNumber-1, inImamLineNumber-1, szAuthCode, INPUT_ALNUMS, AUTH_CODE_SIZE, inValidateString);

#else

    if (getgrid() == 0)
        inResult = inCPACEnterWithMessage(AUTH_CODE_MSG, SCROLL_DISPLAY_FALSE, 3, 6, szAuthCode, INPUT_ALNUMS, AUTH_CODE_SIZE, inValidateString);
    else
        inResult = inCPACEnterWithMessage(AUTH_CODE_MSG, SCROLL_DISPLAY_FALSE, inImamLineNumber-1, inImamLineNumber-1, szAuthCode, INPUT_ALNUMS, AUTH_CODE_SIZE, inValidateString);
#endif /* Else of CITI_PHIL */
    if (inResult >= 0) {
        // strcpy(pobTran->srBRec.szAuthCode, szAuthCode);//leo

        vdCustScroll();
        strcpy(pobTran->srBRec.szAuthCode, szAuthCode);
        memset(szDisplayBuffer, 0, sizeof(szDisplayBuffer));

        vdGetMessageFromFile(TRANS_APP_MSG, szDisplayBuffer);
        if (getgrid() != 0) {
            strcat(szDisplayBuffer, " ");
            strcat(szDisplayBuffer, szAuthCode);
            vdDisplayAt(1, inImamLineNumber, szDisplayBuffer, CLR_EOL);
        } else {
            inTemp = strlen(szDisplayBuffer);
            szDisplayBuffer[inTemp] = 0x01;
            szDisplayBuffer[inTemp + 1] = 0x20;
            szDisplayBuffer[inTemp + 1 + 1] = 0x00;
            vdDisplayAt(1, 4, szDisplayBuffer, CLR_EOL);
            vdDisplayDataStr(szAuthCode, inImamLineNumber, NO_CLEAR, ML_RIGHT);
            vdSGRespMsg(szDisplayBuffer);
        }

        inResult = VS_SUCCESS;
    }
    //  vdDelay (2000);


    return(inResult);
}

/*********************************************************************************************
* @func int | int inCPACConfirmInvAmt (TRANSACTION_OBJECT *pobTran) |
*
*       asks the user to confirm the amount of the selected invoice.
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/

int inCPACConfirmInvAmt(TRANSACTION_OBJECT* pobTran) {
    signed char chAnswer;
    int inResult,
    inOperationCode;
    int inCode;
    long lnDBWhat = DB_FIRST;
    int recchk = 1;
    char chKeyNO = KEY_b;
    char chKeyYES = KEY_a;

    /** /pdebug(("--inConfirmInvAmt--"));*/
    /*
     *      Save Original Transaction Code
     */
    inCode = pobTran->srBRec.inCode;

    inOperationCode = inGGOpCode();
    if (inOperationCode == BATCH_REVIEW_OPERATION)
        return (VS_SUCCESS);

    chKeyNO = KEY_f;
    chKeyYES = KEY_e;

    while (recchk) {
        inRunFunction(pobTran, DISPLAY_REVIEW_REC);
        //vdDisplayReviewRec (pobTran);
        chAnswer = (char) obDisp.inDO_ChooseOne((char *) NULL_CH, (char *) NULL_CH, (char *) pchGetMsg(CPAC_YES_NO_NEXT_MSG), 3, NULL_PFI);
        // CPAC_LINT (char *) added
        if (chAnswer == (char) VS_ESCAPE || chAnswer == (char) KEY_NO) {
            vdSGErrorMessage(0L);
            return(VS_ESCAPE);
        } else if (chAnswer == KEY_YES)
            recchk = 0;
        else {
            lnDBWhat = DB_NEXT;
            switch (pobTran->srBSKey.inKeyIdx) {
            case KEY_INV_NUM:
                if ((inCode == PRE_COMP && pobTran->inOperationCode == PRECOMP_OPERATION) || pobTran->inOperationCode == OPENTAB_DEL_OPERATION) {
                    inResult = inGetOTInvBatchRec(pobTran, KEY_INV_NUM, lnDBWhat); // 1.4
                } else
                    inResult = inGetDCInvBatchRec(pobTran, KEY_INV_NUM, lnDBWhat); // 1.4
                break;

            case KEY_ACC_NUM:
                if ((inCode == PRE_COMP && pobTran->inOperationCode == PRECOMP_OPERATION) || pobTran->inOperationCode == OPENTAB_DEL_OPERATION)
                    inResult = inGetOTKeyBatchRec(pobTran, KEY_ACC_NUM, &pobTran->srBKey, lnDBWhat);
                else
                    inResult = inGetDCKeyBatchRec(pobTran, KEY_ACC_NUM, &pobTran->srBKey, lnDBWhat);
                break;

            default:
                vdSGErrorMessage(CPAC_NO_MATCH_MSG);
                return(VS_ERR);
            }

            if (inResult != VS_SUCCESS) {
                vdDisplayMessageFromFile(CPAC_END_OF_BATCH_MSG, WARNING_MSG);
                vdSGErrorMessage(0L);
            }
        }
    }

    return(VS_SUCCESS);
}

/*********************************************************************************************
* @func int | inCPACUserChoice |
*
*       This function prompts user to choose which search path
*       they want for VOID - Invoice number or last 4 digits of
*       account number.  This is to take into account Open Tab
*       processing.
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
* @end
**********************************************************************************************/

int inCPACUserChoice(TRANSACTION_OBJECT* pobTran) {
    signed char chAnswer;
    long lnDBWhat = DB_FIRST;
    int inTranCode,
    inOperationCode;
    int inRetVal;
    int inLKey = KEY_INV_NUM;

    /** /pdebug (("--inUserChoice--"));*/

    inTranCode = pobTran->srTRTRec.TransactionCode;
    inOperationCode = inGGOpCode();
    if (inOperationCode == BATCH_REVIEW_OPERATION)
        return (VS_SUCCESS);


    if (inTranCode == VOID)/* if Void Transaction */ {
        chAnswer = (char) obDisp.inDO_ChooseOne((char *) NULL_CH, (char *) pchGetMsg(CPAC_VOID_PREVIOUS_MSG), (char *) pchGetMsg(YESNO_MSG5x), 2, NULL_PFI);// CPAC_LINT (char *) added
        if (chAnswer == (char) VS_ESCAPE) {
            vdSGErrorMessage(0L);
            return(VS_ESCAPE);
        } else if (chAnswer == KEY_YES) {
            inLKey = KEY_ALL_RECS;
            if (inGetDCKeyBatchRec(pobTran, inLKey, &pobTran->srBKey, DB_LAST) != VS_SUCCESS) {
                vdDisplayErrorMessage(CPAC_NO_MATCH_MSG);
                return(VS_ERROR);
            }
            inLKey = KEY_INV_NUM;
            pobTran->srBSKey.inKeyIdx = KEY_INV_NUM;

            return (VS_SUCCESS);
        }
    }

    do {
        chAnswer = (char) obDisp.inDO_ChooseOne((char *) NULL_CH, (char *) pchGetMsg(CPAC_RETRIEVE_BY_MSG), (char *) pchGetMsg(CPAC_INV_ACCT_CHOICE_MSG), 2, NULL_PFI);
        if (chAnswer == (char) VS_ESCAPE)
            return(VS_ESCAPE);
        else if (chAnswer == CPAC_CHOICE_INV)
            do {
                inRetVal = inGetInvoiceNumber(pobTran);
                if (inRetVal != VS_SUCCESS) {
                    inRetVal = VS_ERR;
                    break;
                }

                if ((inRetVal = inGetDCInvBatchRec(pobTran, inLKey, lnDBWhat)) != VS_SUCCESS)
                    vdDisplayErrorMessage(CPAC_NO_MATCH_MSG);
            } while (inRetVal != VS_SUCCESS);
        else if (chAnswer == CPAC_CHOICE_ACCT)
            do {
                inRetVal = inGetLastFourAcct(pobTran);
                if (inRetVal != VS_SUCCESS) {
                    inRetVal = VS_ERR;
                    break;
                }

                if ((inRetVal = inGetDCKeyBatchRec(pobTran, KEY_ACC_NUM, &pobTran->srBKey, lnDBWhat)) != VS_SUCCESS)
                    vdDisplayErrorMessage(CPAC_NO_MATCH_MSG);
            } while (inRetVal != VS_SUCCESS);
    } while (inRetVal == VS_ERROR || inRetVal == VS_ESCAPE);

    return (inRetVal);
}

/*********************************************************************************************
* @func int | int inCPACTotTransAmtAlwd(TRANSACTION_OBJECT *pobTran) |
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
* @end
**********************************************************************************************/

int inCPACTotTransAmtAlwd(TRANSACTION_OBJECT* pobTran) {
    int inAllow;

    inAllow = inTotalTransAmtAlwd(pobTran);  //leo_apr27 added
    if (inAllow == VS_ERR)
        return (VS_ERR);
    else
        return (VS_SUCCESS);
}


/*********************************************************************************************
* @func int | int inCPACTotTransAmtAlwd(TRANSACTION_OBJECT *pobTran) |
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
* @end
**********************************************************************************************/

int inCPACTotTransAmtUpdate(TRANSACTION_OBJECT* pobTran) {
    int inUpdate; //, inAllow;  CPAC_LINT_REMOVED

    //  inAllow = inCPACMaxAmountOperation(pobTran);  //leo_may600
    //    if (inAllow == VS_ERR) return (VS_ERR);

    inUpdate = inCPACTransAmtUpdate(pobTran);   //leo_apr27 added
    if (inUpdate == VS_ERR)
        return (VS_ERR);
    else
        return(VS_SUCCESS);
}


/*********************************************************************************************
* @func int | inEditCPACTableOperation |
*       Edit the CPAC/Acquirer  configuration table
*
* @parm TRANSACTION_OBJECT * |pobTran |
*       Transaction object.
*
* @rdesc return values.
* @flag int    |  BRANCH_EXIT
* @end
**********************************************************************************************/

int inEditCPACTableOperation(TRANSACTION_OBJECT* pobTran) {
    char szHostName[30];
    int inMerchantNum;

    memset(szHostName, 0, sizeof(szHostName));

    /** /pdebug (("--vdLoadAmexParams--"));*/

    strcpy(szHostName, szGetHostFileName());//CPAC2.1B
    // strcat(szHostName,".dat");

    inMerchantNum = inGetMerchantNum() - 1;

    inConfRecEdit(szHostName);


    // if (inLoadConfRec(szHostName, SIZE_CPAC_REC, 0, (char *) &srCPAC) != VS_SUCCESS)
    //   vdDisplayMessageFromFile( CPAC_TABLE_ERR_MSG, ERROR_MSG);

    return(BRANCH_EXIT);
}

/*---------------------------------------------------------------------------
    Function     : inCPACGetUserInvNum
    Description  : Gets the User Invoice number.
    Returns      : VS_ERR, VS_SUCCESS, VS_FAILURE or VS_ESCAPE
---------------------------------------------------------------------------*/
int inCPACGetUserInvNum(TRANSACTION_OBJECT* pobTran) {
    char szUsrInvNum[CPAC_USR_INV_NUM_SIZE + 1];
    int inResult,
    inGrid;
    VS_BOOL fUsrInvNum;

    vdLoadCPACParams(&srCPAC);  //Just in case the first tran is an AMEX CPAC_AMEX
    fUsrInvNum = fGetCPACUsrInvNum();
    if (fUsrInvNum == VS_FALSE)
        return(VS_SUCCESS);

    //  BT_TRACE(' ', "Enter UInv Num");
    inGrid = getgrid();

    if (inGrid == 0)
        inResult = inCPACEnterWithMessage(CPAC_USR_INV_NUM_MSG, SCROLL_DISPLAY_FALSE, 3, 6, szUsrInvNum, INPUT_ALNUMS, CPAC_USR_INV_NUM_SIZE, inValidateString);
    else
        inResult = inCPACEnterWithMessage(CPAC_USR_INV_NUM_MSG, SCROLL_DISPLAY_FALSE, 7, 7, szUsrInvNum, INPUT_ALNUMS, CPAC_USR_INV_NUM_SIZE, inValidateString);

    if (inResult == VS_ESCAPE) // CLEAR key processing.
        return (VS_ERR);

    vdSetCPACUserInvNum(&pobTran->srBRec, (unsigned char *) szUsrInvNum);    // (unsigned char *) added

    return(VS_SUCCESS);
}
/*********************************************************************************************
* @func static int | inCPACGetHostTotals |
*
* Get the amount totals from the batch for particular host.
*
* @parm TRANSACTION_OBJECT * |pobTran |
*       Transaction object.
*
* @parm ACCUM_REC * | psrHostTotals |
*       Pointer to accumulator Record structure.
*
* @parm int | inHostIndex |
*       Host index.
*
* @rdesc Returns the success or failure.
* @flag int | VS_SUCCESS
* @flag int | VS_ERR
* @end
**********************************************************************************************/
//leo_may600
static int inCPACGetHostTotals(TRANSACTION_OBJECT* pobTran,ACCUM_REC* psrHostTotals,int inHostIndex) {
    int inRetVal = VS_ERR;

#ifdef ACCUM_DEFINED

    char szFileName[FILENAME_SIZE + 1];
    DB_FILE srDBFPtr;
    ACCUM_REC srAccumRec;
    ACCUM_KEY srAccumKey;
    long lnRecNum = 0L;
    int inTotalSet,
    inTotalType;
    int inTemp;


    if (inLoadHostData(inHostIndex) != VS_SUCCESS)
        return (VS_ERR);

    if (inLoadCSTRec(inGetCurrencyIdx()) != VS_SUCCESS) {
        vdSGErrorMessage(CST_ERR_MSG);
        return (VS_ERR);
    }

    memset((char *) psrHostTotals, 0x00, SIZE_ACCUM_REC);
    for (inTotalSet = 0; inTotalSet < MAX_TOTAL_SETS; inTotalSet++) {
        for (inTotalType = 0; inTotalType < MAX_ACCUM_TYPES; inTotalType++) {
            psrHostTotals->srTotals[inTotalSet].lnCount[inTotalType] = 0;
            psrHostTotals->srTotals[inTotalSet].dbAmount[inTotalType] = 0.0;
            psrHostTotals->srTotals[inTotalSet].dbTip[inTotalType] = 0.0;
            psrHostTotals->srTotals[inTotalSet].dbTax[inTotalType] = 0.0;
            psrHostTotals->srTotals[inTotalSet].dbCashBack[inTotalType] = 0.0;
            psrHostTotals->srTotals[inTotalSet].dbSurCharge[inTotalType] = 0.0;
        }
    }

    vdGetAccumFName(szFileName);
    if (db_open(&srDBFPtr, szFileName, SIZE_ACCUM_KEY, O_RDWR) < 1) {
   //     extern int errno; // imam 

        if (errno != ENOENT) {

            vdSGErrorMessage(BATCH_ERR_MSG);
            return(VS_ERR);
        }
    }

    lnRecNum = 0L;
    while (VS_TRUE) {
        /** /pdebug (("RecNum=%ld",lnRecNum));*/

        if ((inTemp = db_read(&srDBFPtr, &srAccumKey, (char *) &srAccumRec, SIZE_ACCUM_REC, lnRecNum)) != (int) SIZE_ACCUM_REC) {
            /** /pdebug (("Bytes Read=%d ERRNO=%d",inTemp, errno));*/
            break;
        }

        for (inTotalSet = 0; inTotalSet < MAX_TOTAL_SETS; inTotalSet++) {
            for (inTotalType = 0; inTotalType < MAX_ACCUM_TYPES; inTotalType++) {
                psrHostTotals->srTotals[inTotalSet].lnCount[inTotalType] += srAccumRec.srTotals[inTotalSet].lnCount[inTotalType];
                psrHostTotals->srTotals[inTotalSet].dbAmount[inTotalType] += srAccumRec.srTotals[inTotalSet].dbAmount[inTotalType];
                psrHostTotals->srTotals[inTotalSet].dbTip[inTotalType] += srAccumRec.srTotals[inTotalSet].dbTip[inTotalType];
                psrHostTotals->srTotals[inTotalSet].dbTax[inTotalType] += srAccumRec.srTotals[inTotalSet].dbTax[inTotalType];
                psrHostTotals->srTotals[inTotalSet].dbCashBack[inTotalType] += srAccumRec.srTotals[inTotalSet].dbCashBack[inTotalType];
                psrHostTotals->srTotals[inTotalSet].dbSurCharge[inTotalType] += srAccumRec.srTotals[inTotalSet].dbSurCharge[inTotalType];
            }
        }
        lnRecNum++;
    }
    inCloseAccum(&srDBFPtr);
    inRetVal = VS_SUCCESS;

#endif // ACCUM_DEFINED

    return (inRetVal);
}


/*********************************************************************************************
* @func int | inCPACMaxAmountOperation |
*       To limit the maximum amount that can be stored in the accum.
*
* @parm TRANSACTION_OBJECT * |pobTran |
*       Transaction object.
*
* @rdesc return values.
* @flag int    |  BRANCH_EXIT
* @end
**********************************************************************************************/

//leo_may600
int inCPACMaxAmountOperation(TRANSACTION_OBJECT* pobTran) {
    long lnMaxAmt = 2147483646L,
    lnOldTransAmt,
    lnNewTransAmt;
    long lnTotTransAmt;
    double dbSalesTotal,
    dbRefundsTotal;
    int inTranType;

    ACCUM_REC srHostTotals;

    //if (inGetHostNum(pobTran) == VS_SUCCESS)   /* select host */
    //{
    /*  if (inLoadHostData(inGetCDTHostIndex()) == VS_SUCCESS)   sadiq 1.4 changed */
    if (inLoadHostData(inGetHostHandle()) == VS_SUCCESS)  // Bug Fix so that you don't
    {
        // have to select the host to check
        // max amount operation
        if (inCPACGetHostTotals(pobTran, &srHostTotals, inGetHostHandle()) != VS_SUCCESS)
            return (VS_ERR);
    }

    dbSalesTotal = srHostTotals.srTotals[CREDIT_CARD].dbAmount[DEBIT_TRAN] + srHostTotals.srTotals[DEBIT_CARD].dbAmount[DEBIT_TRAN];
    dbRefundsTotal = srHostTotals.srTotals[CREDIT_CARD].dbAmount[CREDIT_TRAN] + srHostTotals.srTotals[DEBIT_CARD].dbAmount[CREDIT_TRAN];

    lnTotTransAmt = pobTran->srBRec.lnBaseTransactionAmount;
    //pobTran->srBRec.lnBaseTransactionAmount = lnTotTransAmt * 10;
    //lnTotTransAmt = lnTotTransAmt * 10;

    inTranType = pobTran->srTRTRec.TransactionCode;
    switch (inTranType) {
    case SALE:
    case SALE_OFFLINE:
    case PRE_AUTH:
        if (inGetTipProcessing())
            lnTotTransAmt = pobTran->srBRec.lnBaseTransactionAmount + pobTran->srBRec.lnTipAmount;
        if ((lnMaxAmt - dbSalesTotal) < lnTotTransAmt) {
            vdDisplayMessageFromFile(CPAC_TRANS_AMT_CROSSED_MSG, WARNING_MSG);
            return(VS_ERR);
        }
        break;

    case ADD_TIP_OFFLINE:
    case TIP_ADJUST:
        if (inGetTipProcessing()) {
            lnTotTransAmt = pobTran->srBRec.lnTipAmount - pobTran->srBRec.lnOldTipAmount;
            if (lnTotTransAmt > 0L) {
                if ((lnMaxAmt - dbSalesTotal) < lnTotTransAmt) {
                    vdDisplayMessageFromFile(CPAC_TRANS_AMT_CROSSED_MSG, WARNING_MSG);
                    return(VS_ERR);
                }
            }
        }
        break;
    case PRE_COMP:
    case ADJUST_REFUND_OFFLINE:
    case ADJUST:
    case CPAC_PHIL_ADJUST:
        //1.4_citiphil_don_26feb
        lnOldTransAmt = pobTran->srBRec.lnOldTotalTransactionAmount;              /* Org Amount for Adjust Txn */
        lnNewTransAmt = pobTran->srBRec.lnBaseTransactionAmount;
        lnTotTransAmt = lnNewTransAmt - lnOldTransAmt;
        if (lnTotTransAmt >= 0L) {
            if ((lnMaxAmt - dbSalesTotal) < lnTotTransAmt) {
                vdDisplayMessageFromFile(CPAC_TRANS_AMT_CROSSED_MSG, WARNING_MSG);
                return(VS_ERR);
            }
        }
        break;

    case REFUND:
        if ((lnMaxAmt - dbRefundsTotal) < lnTotTransAmt) {
            vdDisplayMessageFromFile(CPAC_TRANS_AMT_CROSSED_MSG, WARNING_MSG);
            return(VS_ERR);
        }
        break;
    default:
        break;
    }

    return(VS_SUCCESS);
}

/*---------------------------------------------------------------------------
    Function :    inCPACDemoTrainOperation
    Description : This function checks mode (DEMO) - if set, prompts for clear
                  of demo/training batch, if not, checks to see if any transactions
                  are in batch.  If batch is empty, sets mode to DEMO, otherwise
                  prompts user that batches must be cleared before demo can
                  be turned on.
    Parameters :
    Returns :     VS_ERR, VS_ABORT or VS_SUCCESS
    Globals :     gds
    Notes :
    Modification History :
      #     Date      Who                     Description
    ----- -------- ----------  ---------------------------------------------
 ---------------------------------------------------------------------------*/

int inCPACDemoTrainOperation(TRANSACTION_OBJECT* pobTran) {
    char szOn[MESSAGE_SIZE + 1],
    szOff[MESSAGE_SIZE + 1];
    char szDisplayBuffer[DISP_STR_LEN + 1],
    szHold[MESSAGE_SIZE + 1];
    int inGrid;
    char szChiMsgBuffer[DISP_STR_LEN + 1];

    int inRowLim = inGetRowLim();
    signed int inOnOffValue;

    /** /pdebug(("-inDemoTrainOperation-"));*/

    vdGetMessageFromFile(MSG_ON, szOn);
    vdGetMessageFromFile(MSG_OFF, szOff);

    memset(szHold, 0, sizeof(szHold));

    if (fGetDemoMode())
        strcpy(szHold, szOn);
    else
        strcpy(szHold, szOff);

    memset(szDisplayBuffer, 0, sizeof(szDisplayBuffer));
    vdGetMessageFromFile(DEMO_MODE_MSG, szDisplayBuffer);

    inOnOffValue = obDisp.inDO_ChooseOne(szDisplayBuffer, szHold, (char *) pchGetMsg(ON_OFF_MSG5x), 2, NULL_PFI);

    if (inOnOffValue == VS_ESCAPE)
        return (VS_SUCCESS);
    if ((fGetDemoMode() == VS_TRUE) && (inOnOffValue == 1))
        return(VS_SUCCESS);
    if ((fGetDemoMode() == VS_FALSE) && (inOnOffValue == 2))
        return(VS_SUCCESS);

    if ((fChkAllHostBatches(pobTran) == VS_FALSE) || (fOpenTabEmpty(pobTran) == VS_FALSE)) {
        /*
           if ((obDisp.inDO_ChooseOne((char *)pchGetMsg(BATCH_NOT_EMPTY_ERR_MSG15), (char *)pchGetMsg(BATCHCLEAR_MSG15), (char *)pchGetMsg(YESNO_MSG5x), 2, NULL_PFI)) != KEY_YES)
           {
               vdDisplayMessageFromFile( TXN_CANCELLED, ERROR_MSG);
               return(VS_ESCAPE);
           }
           else
           {
        #ifdef BATCH_DEFINED
                  if (inCPACDeleteAllBatches(pobTran) != VS_SUCCESS)  //changed to CPAC specific batch delete..
                    return(VS_ERR);                               // want to do it our way!

        #endif // BATCH_DEFINED
           }
          */
        inGrid = getgrid();

        if (inGrid == 0) {
            //Chinese version
            memset(szChiMsgBuffer, 0, sizeof(szChiMsgBuffer));
            vdGetMessageFromFile(BATCH_NOT_EMPTY_ERR_MSG15, szChiMsgBuffer);
            vdDisplayAt(1, 2, szChiMsgBuffer, NO_CLEAR);

            memset(szChiMsgBuffer, 0, sizeof(szChiMsgBuffer));
            vdGetMessageFromFile(BATCHCLEAR_MSG15, szChiMsgBuffer);
            vdDisplayAt(1, 3, szChiMsgBuffer, NO_CLEAR);

            if ((obDisp.inDO_ChooseOne(NULL, NULL, (char *) pchGetMsg(YESNO_MSG5x), 2, NULL_PFI)) != KEY_YES) {
                vdDisplayMessageFromFile(TXN_CANCELLED, ERROR_MSG);
                return(VS_ESCAPE);
            } else {
#ifdef BATCH_DEFINED
                if (inCPACDeleteAllBatches(pobTran) != VS_SUCCESS)  //changed to CPAC specific batch delete..
                    return(VS_ERR);                               // want to do it our way!

#endif // BATCH_DEFINED
            }
        } else {
            //English version
            if ((obDisp.inDO_ChooseOne((char *) pchGetMsg(BATCH_NOT_EMPTY_ERR_MSG15), (char *) pchGetMsg(BATCHCLEAR_MSG15), (char *) pchGetMsg(YESNO_MSG5x), 2, NULL_PFI)) != KEY_YES) {
                vdDisplayMessageFromFile(TXN_CANCELLED, ERROR_MSG);
                return(VS_ESCAPE);
            } else {
#ifdef BATCH_DEFINED
                if (inCPACDeleteAllBatches(pobTran) != VS_SUCCESS)  //changed to CPAC specific batch delete..
                    return(VS_ERR);                               // want to do it our way!

#endif // BATCH_DEFINED
            }
        }
    }

    //vdClearNonTitleLines();
    vdClearASCII8x21Window(1, 3, 21, 8);

    if (inOnOffValue == 1)      /* Turn Demo Mode ON */ {
        if (!fGetDemoMode())  /* Ensure Demo Mode is OFF before changing */ {
            strcpy(szHold, szOn);
            vdSetDemoMode(VS_TRUE);//CPAC2.1B
            if (inSaveTCTRec(0) != VS_SUCCESS) {
                vdDisplayMessageFromFile(TCT_ERR_MSG21, ERROR_MSG);
                return(VS_ERROR);
            }  //CPAC2.1B


            trancount = 0;
        }
        vdDispMsgCentered(DEMO_MODE_ON_MSG, obDisp.inInputLine + 1, CLR_EOL);
    } else if (inOnOffValue == 2) /* Turn Demo Mode OFF */ {
        if (fGetDemoMode())   /* Ensure Demo Mode is ON before changing */ {
            strcpy(szHold, szOff);
            vdSetDemoMode(VS_FALSE); //CPAC2.1B

            if (inSaveTCTRec(0) != VS_SUCCESS) {
                vdDisplayMessageFromFile(TCT_ERR_MSG21, ERROR_MSG);
                return(VS_ERROR);
            }  //CPAC2.1B
        }
        vdDispMsgCentered(DEMO_MODE_OFF_MSG, obDisp.inInputLine + 1, CLR_EOL);
    }

    vdDelay(/*2**/PROMPT_DELAY);

    return(VS_SUCCESS);
}


/*---------------------------------------------------------------------------
    Function :    int inCPACChkBatchEmpty(TRANSACTION_OBJECT *pobTran)
    Description :
    Parameters :
    Returns :
    Globals :
    Notes :
    Modification History :
      #     Date      Who                     Description
    ----- -------- ----------  ---------------------------------------------
 ---------------------------------------------------------------------------*/


int inCPACChkBatchEmpty(TRANSACTION_OBJECT* pobTran) {
    if (fChkHostBatches(pobTran, inGetMerchantNum() - 1)) {
		LOG_PRINTFF((0x08L, "BATCH EMPTY - Merchant[%d]", inGetMerchantNum()-1));
        vdDisplayMessageFromFile(BATCH_EMPTY_MSG, WARNING_MSG);
        return(VS_ERR);
    }

    return (VS_SUCCESS);
}

#if 0
/*********************************************************************************************
* @func VS_BOOL | inRange |
*       Determines if a value is within a specified range
*
* @parm int | inVal |
*       The value to be tested
*
* @parm int | inLow |
*       Low range
*
* @parm int | inHigh |
*       High range
*
* @rdesc return values.
* @flag VS_BOOL |  VS_TRUE or VS_FALSE
* @end
**********************************************************************************************/

int inCPACRange(char* pchValue)
{
    if(strcmp(pchValue,"\0"))
        return(VS_FALSE);

    else return (VS_TRUE);
}
#endif /* 0 */

/*********************************************************************************************
* @func int | inCPACBatchClearOperation |
*
*       Batch Clear Operation - prompts for one or all
*       Hosts to be deleted, deletes batchs as appropriate.
*       If an individual Host batch is deleted the corresponding
*       transactions from the Open Tab batch are also deleted.
*
* @parm TRANSACTION_OBJECT *    | pobTran |
*
* @rdesc Return values.
*
* @flag int     |   - VS_SUCCESS
*                   - VS_ERR
* @end
**********************************************************************************************/

#define     CLEAR_EMPTY             0
#define     CLEAR_ABORT             1
#define     CLEAR_ALL_HOSTS     2
#define     CLEAR_ONE_MERCH    3

int inCPACBatchClearOperation(TRANSACTION_OBJECT* pobTran) {
    signed int inResult = 0;
    int inNumberOfMerchants;
    char chBCOperation = CLEAR_EMPTY;

    /**/pdebug(("--inBatchClearOperation--"));/**/

    /* If the batch is not empty, continue... */
    if (!fChkAllHostBatches(pobTran) || !fOpenTabEmpty(pobTran) || !fReversalsEmpty()) {
        chBCOperation = CLEAR_ABORT;

        inNumberOfMerchants = inSelectOneAllMID(pobTran, fGetMultiMerchPrompt()); //1.4

        if (inNumberOfMerchants == 0)
            chBCOperation = CLEAR_ABORT;
        else
            chBCOperation = CLEAR_ALL_HOSTS;
        //The following code was commented.. because it never used to clear the
        //tabs.. Now we clear all batches for all merchants whatever they are.

        /* clear all hosts for 1 merchant   */
        /*    if (inNumberOfMerchants == 1)
                chBCOperation = CLEAR_ONE_MERCH; */

        /* clear all hosts for all merchants */
        /*    if (inNumberOfMerchants > 1) */
    }

    /* Close Tab Batch  opened above by fOpenTabEmpty() */
    vdCloseTabBatch(pobTran);

    if (chBCOperation == CLEAR_ALL_HOSTS || chBCOperation == CLEAR_ONE_MERCH) {
        /* Prompt to confirm */
        if ((inResult = obDisp.inDO_ChooseOne((char *) NULL_CH, pchGetMsg(CONFIRM_MSG15), pchGetMsg(YESNO_MSG5x), 2, NULL_PFI)) != KEY_YES)  // CPAC_LINT_ADDED (char *)
            chBCOperation = CLEAR_ABORT;
    }

    /*
     *      Clear the Batch(es) and/or display error based on
     *      above selections
     */
    switch (chBCOperation) {
    case CLEAR_ONE_MERCH:
        /* delete all hosts for one merch */
        if (inClrBatch(pobTran, CLEAR_BATCH, VS_TRUE) != VS_ERR) {
            inResult = VS_SUCCESS;
            if (inCPACIncBatchNum() == VS_ERR)
                return(VS_ERR);
        }
        break;
    case CLEAR_ALL_HOSTS:
        /*
         *      Delete all batches for all merchants!
         */
        inResult = inCPACDeleteAllBatches(pobTran);
        break;
    case CLEAR_EMPTY:
        /*
         *      Batch is empty, display error...
         */
        vdDisplayMessageFromFile(BATCH_EMPTY_MSG, WARNING_MSG);
    case CLEAR_ABORT:
        inResult = VS_ESCAPE; // 1.4
        break;
    }

    /*
     *      Check for error during processing
     */
    if (inResult != VS_SUCCESS && inResult != VS_ESCAPE) // 1.4
    {

        vdDisplayMessageFromFile(BATCH_ERR_MSG, ERROR_MSG);
        vdDelay(PROMPT_DELAY);
    }

    return(inResult);
} /* end of inBatchClearOperation() */


//leo_may1800
/*********************************************************************************************
* @func int | inCPACDeleteAllBatches |
*
*       Delete All Batches.
*       If an individual Host batch is deleted the corresponding
*       transactions from the Open Tab batch are also deleted.
*
* @parm TRANSACTION_OBJECT *    | pobTran |
*
* @rdesc Return values.
*
* @flag int     |   - VS_SUCCESS
*                   - VS_ERR
* @end
**********************************************************************************************/

int inCPACDeleteAllBatches(TRANSACTION_OBJECT* pobTran) {
    int /* inCnt,*/ inCnt2;   //CPAC_LINT_REMOVED
    //HDT_REC srTempHDTRec;
    //MHT_REC srTempMHTRec;
    //char    pchBFName[FILENAME_SIZE + 1];
    //int     inHostNum;

    /**/pdebug(("--inDeleteAllBatches--"));/**/

    for (inCnt2 = 0; inCnt2 < inGetMITTotRecs(); inCnt2++) {
        vdCloseDCBatch(pobTran);

        /**/pdebug(("inCnt2=%d", inCnt2));/**/
        inLoadMITRec(inCnt2);

        if (inDeleteOpenTabBatch(pobTran) != VS_SUCCESS)
            continue;

        if (inClrBatch(pobTran, CLEAR_BATCH, VS_TRUE) == VS_ERR)
            continue;
        else {
            if (inCPACIncBatchNum() == VS_ERR)
                return(VS_ERR);
        }
    }

    return(VS_SUCCESS);
}


/*********************************************************************************************
* @func int | inCITIValidateString |
*             Validates against ENTER Key only entry.
*
* @parm char * | szInputPwd |
*       Input password
*
* @rdesc
* @flag int | VS_SUCCESS
* @flag int | VS_ERR
* @end
**********************************************************************************************/

int inCITIValidateString(char* szString) {
    if (strlen(szString) != AUTH_CODE_SIZE) {
        vdSGErrorMessage(INVALID_ENTRY_MSG);
        return (VS_ERR);
    }

    return(VS_SUCCESS);
}




/*-----------------------------------------------------------------------------
* Routine Name : int inCPACIncBatchNum(void)
* Description  : Updates the CPAC based on the Trans type with the Transaction
*                Amt entered
* Inputs       : None
* Outputs      : None
* Returns      : VS_SUCCESS/VS_ERR
* Notes        :
*---------------------------------------------------------------------------*/
int inCPACIncBatchNum(void) {
    MHT_REC srTempMHTRec;
    HDT_REC srTempHDTRec;
    char pchBFName[FILENAME_SIZE + 1];
    int inHostNum;

    for (inHostNum = 0; inHostNum < MAX_HOSTS; ++inHostNum) {
        if (inLoadConfRec(HDT_FILE_NAME, SIZE_HDT_REC, inHostNum, (char *) &srTempHDTRec) != VS_SUCCESS) {
            vdDisplayMessageFromFile(HDT_ERR_MSG21, WARNING_MSG);
            return(VS_ERR);
        }
        if (srTempHDTRec.fHDTCustomBit1) {
            vdGetMHTFileName(pchBFName);
            if (inLoadConfRec(pchBFName, SIZE_MHT_REC, inHostNum, (char *) &srTempMHTRec) != VS_SUCCESS) {
                vdSGErrorMessage(MHT_ERR_MSG21);
                return(VS_ERR);
            }
            //if (!(fGetTCTDemoMode())
            srTempMHTRec.lnBatchNum++;
            if (inSaveConfRec(pchBFName, SIZE_MHT_REC, inHostNum, (char *) &srTempMHTRec) != VS_SUCCESS) {
                vdSGErrorMessage(MHT_ERR_MSG21);
                return(VS_ERR);
            }
        }
    }
    return (VS_SUCCESS);
}

/*-----------------------------------------------------------------------------
* Routine Name : int inCPACCheckLongAmtOverflow(TRANSACTION_OBJECT *pobTran)
* Description  : Updates the CPAC based on the Trans type with the Transaction
*                Amt entered
* Inputs       : None
* Outputs      : None
* Returns      : VS_SUCCESS/VS_ERR
* Notes        :
*---------------------------------------------------------------------------*/
int inCPACCheckLongAmtOverflow(TRANSACTION_OBJECT* pobTran) {
    int inAllow;

    inAllow = inCPACMaxAmountOperation(pobTran);  //leo_may600
    if (inAllow == VS_ERR)
        return (VS_ERR);
    else
        return (VS_SUCCESS);
}
/*********************************************************************************************
* @func int | inValidateSwipedCard |
*
*		Clear pobTran->srBRec.fManual.  Read card information from card reader.  Validate data
*		length.  Call card_parse() with track priorty based on inGetTCTTrackNumber().
*		Call inValInteracDebit().  Call inGetCardBin().  Load loyalty information if neccessary.
*		Load fields pobTran->srBRec.szPAN and pobTran->srBKey.lnLast5.  Call vdDetermineCardType ().
*		Validate PINPAD present if necessary.  Process Track I and Track II information if necessary.
*		Validate Track II present for EBT and DEBIT.
*
*		FIELD ID:		VALIDATE_MANUAL_NO		 0x0044
*
* @parm TRANSACTION_OBJECT *	| pobTran	|
*
* @rdesc Return values.
* @flag int    |  VS_SUCCESS	|
* @flag int    |  VS_ERR		|
* @end
**********************************************************************************************/

int inCPACValidateSwipedCard (TRANSACTION_OBJECT *pobTran)
{
int		inResult,
		inStatus = VS_SUCCESS;
		//inTrackNumber; 1.4


VS_BOOL fTrack2Valid = VS_FALSE;
VS_BOOL fTrack1Valid = VS_FALSE;
char	chCardBuffer[CARD_SIZE + 1];
struct	TRACK srCardData; //, srCPACCardData; 1.4 _LINT
/* PFI		pinGetCardBin; 1.4 */
PFI_TO_PSZ_F	pinGetCardBin; // mofified in 1.4
// to be added in 1.4 PFI_PSZ     	pinCheckExpDate;
char	szCardLabel[CLABEL_SIZE + 1];  //CPAC_AMEX
char    szTrackPriority[TRACKS_ALLOWED+1]; //1.4
char    szTracksReq[TRACKS_ALLOWED+1];     //1.4
//PRINTER_OBJECT *pobPrinter;

struct TRACK srImamCardData;  //

    if ((pinGetCardBin = inGetFunctionPointer(GET_CARD_BIN)) == NULL_PFI)
    {
		/**/pdebug (("inGetFunctionPointer pinValSwiped Error"));/**/
        return(VS_ERR);
    }

	/**/pdebug(("--inValidateSwipedCard--"));/**/
	pobTran->srBRec.fManual = VS_FALSE;

/** changed 03/30/99 **/

    inResult = read(hCardReader, chCardBuffer, CARD_SIZE);
    #ifdef SHELL_FLEET

	    for (i=0;i<CARD_SIZE;i++)
		szKbdBuf[i] = chCardBuffer[i]; 	/*	Saritha_b1 added on 2nd July for Shell Application.This value is used in Shellsrc.C file */
    #endif

	if(inResult <= 6)
	{
		/* -- ba1: increment the card read error counter -- */
	     ACTIVITY_LOG ("Bad Swipe");
		INCREMENT_CARD_ERROR;
		vdSGErrorMessage(CARDREAD_ERR_MSG);
		return(VS_ERR);
	}

	/* inTrackNumber = inGetTCTTrackNumber();  //1.4
	if (!(inTrackNumber && BOTH_TRACKS_MASK))
	{
		INCREMENT_CARD_ERROR;
 		vdSGErrorMessage(INVALID_TCT_TRACK_MSG21);
 		return(VS_ERR);
	} */ //1.4
	strcpy ( szTrackPriority , szGetTracks());

	if (strpbrk(szTrackPriority,"123")==NULL_CH) {
		INCREMENT_CARD_ERROR;
 		vdSGErrorMessage(INVALID_TCT_TRACK_MSG21);
 		return(VS_ERR);
	}

	/* Parse card to get acct number to determine if debit
	   handle card parse error */

	{//LIEM to get card holder name
		memset((void *)&srImamCardData, 0x00, sizeof(srImamCardData));  
		inResult = card_parse(chCardBuffer, &srImamCardData, "1");
		if (inResult < 0) {
			memset((void *)&srImamCardData, 0x00, sizeof(srImamCardData));
		} 
		LOG_PRINTFF((0x08L, "Card Holder : [%s]", srImamCardData.name));
	}//end of add
    inResult = card_parse(chCardBuffer, &srCardData, szTrackPriority);
	if(inResult < 0 )
	{
		INCREMENT_CARD_ERROR;
		vdGetCardParseError ((long)inResult);
 		return(VS_ERR);
	}

 /*   inResult = card_parse(chCardBuffer, &srCPACCardData, "2");
	if(inResult < 0 )
	{
		INCREMENT_CARD_ERROR;
		vdGetCardParseError ((long)inResult);
 		return(VS_ERR);
	}*/ //1.4

/*	strcpy(srCardData.acct, srCPACCardData.acct);  */ // 1.4 card swipe fix

   /* inValInteracDebit (pobTran, &srCardData); */ // commented in core also 1.4

	/**/pdebug(("card parse ret %d", inResult));/**/
    if ((inResult = pinGetCardBin (pobTran, srCardData.acct, VS_FALSE)) <= VS_ERR)
    {
		return(inResult);
	}

#ifdef VXEMVAPP
	strcpy(pobTran->szServiceCode, srCardData.type);
#else
    /* Gw fix from 2.5 - save service code for FPS no auth requires txn.*/
	strcpy(pobTran->srBRec.szAuthCode, srCardData.type);
#endif /* VXEMVAPP */
	strcpy(pobTran->srBRec.szPAN, srCardData.acct);

    /* Form the Last 5 Acct # to Key Structure */
    //strlcpy(pobTran->srBKey.SAcctNum,&pobTran->srBRec.szPAN[strlen(pobTran->srBRec.szPAN) - 5],(FIVE_DIGIT_ACCT + 1));
    pobTran->srBKey.lnLast4 = str2long (&pobTran->srBRec.szPAN[strlen(pobTran->srBRec.szPAN) - LAST4_DIGIT_ACCT]);

	vdDetermineCardType(pobTran, &srCardData);					/* Card Detection */
    if((pobTran->srBRec.inTranCardType == DEBIT_CARD ||
        pobTran->srBRec.inTranCardType == EBT_CARD)
#ifdef PINPAD_DEFINED
            &&
        ((!gfPPadPresent) || (inGetPINPadType() == NO_PINPAD))
#endif /* PINPAD_DEFINED */
        )
    {
        //vdDisplayMessageFromFile( TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
    	vdSGErrorMessage(PINPAD_ERR_MSG21);
		INCREMENT_PINPAD_ERROR;
        return(VS_ERR);
    }
	//strcpy (szTracksReq,szGetTracks());  //: this should be enough?
	strcpy (szTracksReq,szGetTracksRequired());  //spqalog097

	if ( strpbrk(szTrackPriority,"1")!= NULL_CH )
	{
       inResult = card_parse(chCardBuffer, &srCardData, "1");

		if(inResult == 1)
		{
			inStatus = inCheckTrackOneData(&srCardData, inResult);
			
			if (inStatus == VS_ERR)
        	{
        			
        		//LeeChyi - 27122005: START
        		if ((strpbrk(szTracksReq,"2")!=NULL_CH)){
        			//Track1 is optional	 since Track 2 is also required.
        			LOG_PRINTF(("Check Track 1 Error. Obtain track 2"));
        		}
        		//LeeChyi - END
			 	else if ((strpbrk(szTrackPriority,"23")==NULL_CH) || (strpbrk(szTracksReq,"1")!=NULL_CH))
    				return VS_ERR;		  /* Error Message is being set in inChecTranOneData */
	        }
    	    else
        	{
            	fTrack1Valid = VS_TRUE;
               	memcpy(pobTran->srBRec.stT1Data, (char *) srCardData.track, TRACK1_SIZE);/* Store Track 1  */
               	pobTran->srBRec.fT1Data = VS_TRUE; //JOEY /*Added since Track1 was not getting stored in the batch... sowmya*/
 				strcpy(pobTran->srBRec.szCHolder, srCardData.name);
//CPAC_AMEX
				pobTran->srBRec.fCHolder = VS_TRUE;
				strcpy (szCardLabel, szGetCardLabel());
				//vdGetCardLabel(szCardLabel);	/* AMEX expiry date checking not required JD */
				
				if ((strncmp(szCardLabel, "AMEX", 4) != 0))
				{
    			if ( fGetExpDtReqd() )
    			{
    				inResult = inValidateExpDate(srCardData.exp);
      				if (inResult != VS_SUCCESS)
	    					return(inResult);
	    			}
	    	    }
    			strcpy(pobTran->srBRec.szExpDate, srCardData.exp);
       		}
       	}
       	else
       	{
       		//LeeChyi - 27122005: START
       		if ((strpbrk(szTracksReq,"2") != NULL_CH)){
        			//Track1 is optional	 since Track 2 is also required.
        			LOG_PRINTF(("Card Parse Track 1 Error. Obtain track 2"));
        		}
        		//LeeChyi - END
       		else if ((strpbrk(szTrackPriority,"23")==NULL_CH) || (strpbrk(szTracksReq,"1")!=NULL_CH))
       		{
       			vdGetCardParseError((long)inResult);
       			return VS_ERR;
       		}
	}
	}

	if ( fTrack1Valid == VS_FALSE )
    	{
	    strcpy(pobTran->srBRec.szCHolder, "");
	    pobTran->srBRec.fCHolder = VS_FALSE;
	}

	if (strpbrk(szTrackPriority,"2")!=NULL_CH )
	{
		inResult = card_parse(chCardBuffer, &srCardData, "2");
		/**/pdebug(("card parse ret %d", inResult));/**/
		inStatus = inCheckTrackTwoData(&srCardData, inResult);
		if ( inStatus == VS_ERR )
		{
		    if ( fTrack1Valid == VS_FALSE )
    		   	return VS_ERR;	  /* Error Message is being set in inChecTranOneData */

		    /*Praveen_ 20/01/2003_ Fix for track2 Bug*/
           	   if (strpbrk(szTracksReq,"2") != NULL_CH)
                	return VS_ERR;

		}
		else
        {
            fTrack2Valid = VS_TRUE;
    		/**/pdebug(("Track2Valid"));/**/
           	memcpy(pobTran->srBRec.stT2Data, (char *) srCardData.track, TRACK2_SIZE);/* Store Track 2  */
           	pobTran->srBRec.fT2Data = VS_TRUE;//joey /*Added since Track 2 was not getting stored in the batch... sowmya*/
		    if ( fTrack1Valid == VS_FALSE )
 					strcpy(pobTran->srBRec.szCHolder, "");
//CPAC_AMEX
			strcpy (szCardLabel, szGetCardLabel());
	//		vdGetCardLabel(szCardLabel);	/* AMEX expiry date checking not required JD */
			if ((strncmp(szCardLabel, "AMEX", 4) != 0))
			{
    		if ( fGetExpDtReqd() )
    		{
				inResult = inValidateExpDate(srCardData.exp);
    			if(inResult != VS_SUCCESS)
	    			return(inResult);
	    	}
			}
/* LENIN  Check above lines */
    		strcpy(pobTran->srBRec.szExpDate, srCardData.exp);
       }
	}

    if ((pobTran->srBRec.inTranCardType == DEBIT_CARD ||
         pobTran->srBRec.inTranCardType == EBT_CARD) && fTrack2Valid != VS_TRUE)
        return(VS_ERR);

	{//LIEM : add to get card holder name
		if (strlen(srImamCardData.name)>0) {  
			strcpy(pobTran->srBRec.szCHolder, srImamCardData.name);
			pobTran->srBRec.fCHolder = VS_TRUE;
		} 
	}// end of add

    #ifdef ICICI

		// add transaction validation functions here.
    		switch(pobTran->srBRec.inCode)
		{
			case PRE_AUTH:
			case IMAM_CARDVER:
			case AUTH_ONLY:
							if(fGetCDTCustomBit1() == VS_FALSE)
							{
								vdSGErrorMessage(TRANS_NOT_ALLWD_ERR_MSG);
								return (VS_ERR);
							}
							break;
			case SALE_OFFLINE:
							if(fGetCDTCustomBit2() == VS_FALSE)
							{
								vdSGErrorMessage(TRANS_NOT_ALLWD_ERR_MSG);
								return (VS_ERR);
							}
							break;
			case REFUND:
							if(fGetCDTCustomBit3() == VS_FALSE)
							{
								vdSGErrorMessage(TRANS_NOT_ALLWD_ERR_MSG);
								return (VS_ERR);
							}
							break;
		}
	#endif  /* ICICI  */

	return (VS_SUCCESS);
}

/*********************************************************************************************
* @func int | int inCITICheckBatchTotals(TRANSACTION_OBJECT *pobTran) |
*
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
* @flag int    |  VS_SUCCESS    |
* @flag int    |  VS_ERR        |
* @end
**********************************************************************************************/


int inCITICheckBatchTotals(TRANSACTION_OBJECT* pobTran) {
    int /*inChar, */ inRetVal;
    double dbSalesTotal,
    dbRefundsTotal;
    //char szSalesAmt[AMT_SIZE + 1];
    //char szRefundsAmt[AMT_SIZE + 1];
    //char szTotalAmt[AMT_SIZE + 1];
    ACCUM_REC srHostTotals;

    /** /pdebug(("--inBatchTotalsOperation--"));*/

    /* select host */
    inLoadMITRec(inGetHostHandle());
    inLoadMHTRec(inGetHostHandle());
    /*    if (inLoadHostData(inGetCDTHostIndex()) == VS_SUCCESS) sadiq 1.4 changed */
    if (inLoadHostData(inGetHostHandle()) == VS_SUCCESS) // 1.4 Lenin
    {
        if (inCPACGetHostTotals(pobTran, &srHostTotals, inGetHostHandle()) != VS_SUCCESS)
            return (VS_ERR);
    } else
        return (VS_ERR);

    inRetVal = inCPACChkBatchEmpty(pobTran);
    if (inRetVal == VS_ERR)
        return (VS_ERR);

    dbSalesTotal = srHostTotals.srTotals[CREDIT_CARD].dbAmount[DEBIT_TRAN] + srHostTotals.srTotals[DEBIT_CARD].dbAmount[DEBIT_TRAN];
    dbRefundsTotal = srHostTotals.srTotals[CREDIT_CARD].dbAmount[CREDIT_TRAN] + srHostTotals.srTotals[DEBIT_CARD].dbAmount[CREDIT_TRAN];

    if ((dbSalesTotal == 0) && (dbRefundsTotal == 0)) {
        vdSGErrorMessage(CITI_IND_NULL_TOTALS_MSG);
        return (VS_ERR);
    }

    return (VS_SUCCESS);
}



/*********************************************************************************************
* @func int | int inCITIGetBatchNumAndCheck(TRANSACTION_OBJECT *pobTran) |
*
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
* @flag int    |  VS_SUCCESS    |
* @flag int    |  VS_ERR        |
* @end
**********************************************************************************************/


int inCITIGetBatchNumAndCheck(TRANSACTION_OBJECT* pobTran) {
    char szBatchNumber[BATCH_NUM_SIZE + 1];
    char szLocBuf[1 + 1];
    int inResult;
    int inRowLim = inGetRowLim();

    SETT_REC srLocSRec;
    SETT_KEY srLocSKey;


    szBatchNumber[0] = '\0';
    memset(szLocBuf, NULL_CH, sizeof(szLocBuf));

    while (1) {
        szBatchNumber[0] = '\0';

        inResult = inEnterWithMessage(BATCH_NUM_MSG, SCROLL_DISPLAY_FALSE, szBatchNumber, INPUT_NUMS, inGetBatchNumSize(), NULL_PFI);
        window(obDisp.inHomeCol, obDisp.inTitleLine, inRowLim, obDisp.inCharsPerColumn);

        if (inResult <= 0) {
            vdSGErrorMessage(TXN_CANCELLED);
            return (VS_ERR);
        }

        strcpy(pobTran->szBatchNum, szBatchNumber);
        pad(pobTran->szBatchNum, pobTran->szBatchNum, '0', inGetBatchNumSize(), RIGHT);

        strlcpy(pobTran->szSettDate, szLocBuf, DATE_SIZE);

        if (inGetBatchNumSettRec(pobTran, &srLocSRec, &srLocSKey) != VS_SUCCESS) {
            vdDisplayMessageFromFile(NO_DATA_MSG, WARNING_MSG);
            //pobTran->szBatchNum[0] = '\0';
            memset(pobTran->szBatchNum, NULL_CH, inGetBatchNumSize());
        } else
            break;
    }
    memset(pobTran->szSettDate, NULL_CH, sizeof(pobTran->szSettDate));
    return (VS_SUCCESS);
}


int inSingleBatchClearOperation(TRANSACTION_OBJECT* pobTran) {
    signed int inResult = 0;
    //int     inCurrentBatchRecord;             CPAC_LINT_REMOVED
    //int     inNumberOfRecordsinBatch;         CPAC_LINT_REMOVED
    int inNumberOfMerchants;
    char chBCOperation = CLEAR_EMPTY;
    //char    szHostName[HOST_NAME_SIZE + 1];   CPAC_LINT_REMOVED



    /* If the batch is not empty, continue... */
    if (!fBatchEmpty(pobTran, VS_TRUE) || !fOpenTabEmpty(pobTran) || !fchkrevfile(pobTran)) {
        chBCOperation = CLEAR_ABORT;

        inNumberOfMerchants = inSelectOneAllMID(pobTran, fGetMultiMerchPrompt()); // 1.4
    } else // If batch is empty
    {
        vdDisplayMessageFromFile(BATCH_EMPTY_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }

    vdCloseTabBatch(pobTran);

#if 0
       /* Prompt to confirm normal batch delete */
       if ( (inResult = obDisp.inDO_ChooseOne((char *)NULL_CH,
            pchGetMsg(CONFIRM_MSG15),
            pchGetMsg(YESNO_MSG5x), 2, NULL_PFI)) != KEY_YES )  // CPAC_LINT_ADDED (char *)
       {
           chBCOperation = CLEAR_ABORT;
           vdDisplayMessageFromFile( TXN_CANCELLED, WARNING_MSG);// 1.4
           vdDelay(PROMPT_DELAY);// 1.4
           return (VS_ESCAPE);// 1.4
       }
#endif /* 0 */

    if (!fOpenTabEmpty(pobTran)) {
        /* Prompt to confirm for PreAuth batch delete 1.4 */

        inResult = obDisp.inDO_ChooseOne((char *) NULL_CH, pchGetMsg(DELETE_OPEN_TAB_MSG15), pchGetMsg(YESNO_MSG5x), 2, NULL_PFI);
        if ((inResult != KEY_YES) || (inResult == KEY_NO)) // CPAC_LINT_ADDED (char *)
        {
            chBCOperation = CLEAR_ABORT;
            vdDisplayMessageFromFile(TXN_CANCELLED, WARNING_MSG);// 1.4
            vdDelay(PROMPT_DELAY);// 1.4
            return (VS_ESCAPE);// 1.4
        }

        inResult = inDeleteOpenTabBatch(pobTran);
    }


    if (!fBatchEmpty(pobTran, VS_TRUE) || !fchkrevfile(pobTran)) {
        /* Prompt to confirm normal batch delete */
        if ((inResult = obDisp.inDO_ChooseOne((char *) NULL_CH, pchGetMsg(CONFIRM_MSG15), pchGetMsg(YESNO_MSG5x), 2, NULL_PFI)) != KEY_YES)  // CPAC_LINT_ADDED (char *)
        {
            chBCOperation = CLEAR_ABORT;
            vdDisplayMessageFromFile(TXN_CANCELLED, WARNING_MSG);// 1.4
            vdDelay(PROMPT_DELAY);// 1.4
            return (VS_ESCAPE);// 1.4
        }

        if (inClrBatch(pobTran, CLEAR_HOST, VS_TRUE) != VS_ERR) {
            inResult = VS_SUCCESS;
            if (inCPACIncBatchNum() == VS_ERR)
                return(VS_ERR);
        }
    }

#if 0
        /* Prompt to confirm for PreAuth batch delete 1.4 */
       if ( (inResult = obDisp.inDO_ChooseOne((char *)NULL_CH,
            pchGetMsg(DELETE_OPEN_TAB_MSG15),
            pchGetMsg(YESNO_MSG5x), 2, NULL_PFI)) != KEY_YES )  // CPAC_LINT_ADDED (char *)
       {
           chBCOperation = CLEAR_ABORT;
           vdDisplayMessageFromFile( TXN_CANCELLED, WARNING_MSG);// 1.4
           vdDelay(PROMPT_DELAY);// 1.4
           return (VS_ESCAPE);// 1.4
       }

        inResult = inDeleteOpenTabBatch(pobTran);

#endif /* 0 To change the position of this prompt */

    if (inResult != VS_SUCCESS) {

        vdDisplayMessageFromFile(BATCH_ERR_MSG, ERROR_MSG);
        vdDelay(PROMPT_DELAY);
    }

    return(inResult);
}

int inCPACShowMemoryLeftOperation(TRANSACTION_OBJECT* pobTran) {
    struct fs_size srFS;
    char buffer[30];

    clrscr();
    dir_get_sizes("I:", &srFS);
    sprintf(buffer, "RAM SIZE   = %ld.", (srFS.InUse + srFS.Avail));
    vdDisplayDataStr(buffer, 1, NO_CLEAR, ML_LEFT);
    sprintf(buffer, "I: AVAIL   = %ld.", (srFS.Avail));
    vdDisplayDataStr(buffer, 2, NO_CLEAR, ML_LEFT);
    dir_get_sizes("F:", &srFS);
    sprintf(buffer, "FLASH SIZE = %ld.", (srFS.InUse + srFS.Avail));
    vdDisplayDataStr(buffer, 3, NO_CLEAR, ML_LEFT);
    sprintf(buffer, "F: AVAIL   = %ld.", (srFS.Avail));
    vdDisplayDataStr(buffer, 4, NO_CLEAR, ML_LEFT);
    sprintf(buffer, "HEAP SIZE  = %ld.", _heapsize);
    vdDisplayDataStr(buffer, 5, NO_CLEAR, ML_LEFT);
    sprintf(buffer, "MAX HEAP   = %ld.", _heap_max());
    vdDisplayDataStr(buffer, 6, NO_CLEAR, ML_LEFT);
    sprintf(buffer, "STACK SIZE = %ld.", _stacksize);
    vdDisplayDataStr(buffer, 7, NO_CLEAR, ML_LEFT);
    sprintf(buffer, "MAX STACK  = %ld.", _stack_max());
    vdDisplayDataStr(buffer, 8, NO_CLEAR, ML_LEFT);
    inWaitKey(inGetIdleTimeOut());

    pdebug(("MAX Heap used = %ld.", _heap_max()));
    pdebug(("MAX Stack used = %ld.", _stack_max()));

    return(BRANCH_EXIT);
}

//Kelvin_F2 --- start: Tip Adjust Input By Total (Hong Kong Style)
#ifdef HKGM
/*********************************************************************************************
* @func int | inHKGMTipAdjust |
*
*       The tip amount is adjusted specially for HKGM.. formatting and giving cur.symbol
*       (enter the new total amount instead of new tip amount)
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/

int inHKGMTipAdjust(TRANSACTION_OBJECT* pobTran) {
    char szAmount[AMT_SIZE + 1];
    char szDisplaySymbol[CUR_SYMBOL_SIZE + 1];
    char szDisplayBuffer[DISP_STR_LEN + 1];
    long lnBaseAmt,
    lnOldTipAmt,
    lnOldTotalAmt;
    //unsigned long ulTimer;   CPAC_LINT_REMOVED
    int inResult,
    inAmtInputLine,
    inAllow;
    int inGrid,
    inCol;  // CPAC_ML

    inGrid = getgrid();

    if (inGrid == 0)
        inAmtInputLine = 3;
    else
        inAmtInputLine = 7;

    szAmount[0] = '\0';
    memset(szDisplayBuffer, 0, sizeof(szDisplayBuffer));

    strcpy(szDisplaySymbol, szGetCurSymbol());

    pobTran->inTransactionCode = TIP_ADJUST;
    /* pj1 save old amount first */
    pobTran->srBRec.lnOldTotalTransactionAmount = pobTran->srBKey.lnTotalOfTransactionAmount;
    pobTran->srBRec.lnOldTipAmount = pobTran->srBRec.lnTipAmount;

    /* Display old tip amount */
    //sprintf(szAmount,SUBSTITUTE_LD, pobTran->srBRec.lnTipAmount);
    //vdPutDecPoint(szAmount);
    //    vdFormatAmount(szAmount, VS_TRUE);                    //leo_apr11 Added
    //      vdGetMessageFromFile( TIP_AMOUNT_MSG,szDisplayBuffer);

    //V2.2 Enhace on Tip adjust display the old total amount.
    sprintf(szAmount, SUBSTITUTE_LD, pobTran->srBKey.lnTotalOfTransactionAmount);
    vdFormatAmount(szAmount, VS_TRUE);
    vdGetMessageFromFile(O3200_OLD_AMOUNT_MSG, szDisplayBuffer);

    if (inGrid == 0) {
        // CPAC_ML
        obDisp.inDetailLine = 2;
        vdDisplayAt(obDisp.inHomeCol, obDisp.inDetailLine, szDisplayBuffer, CLR_EOL);
        inCol = 21 - strlen(szAmount) + 1;
        inMLDisplayAt(inCol, 4, szAmount, NO_CLEAR, ML_USE_GIVEN_FONT, ML_ACTION_FONT, "F:ASC8X21.VFT");
    } else {
        obDisp.inDetailLine = 5;
        vdDisplayAt(obDisp.inHomeCol, obDisp.inDetailLine, szDisplayBuffer, CLR_EOL);
        vdDispStrAtRight(szAmount, obDisp.inDetailLine, NO_CLEAR);
    }

    /* Prompt for new tip amount */
    szAmount[0] = '\0';
    //vdGetMessageFromFile( NEW_TIP_AMT_MSG,szDisplayBuffer);

    vdGetMessageFromFile(O3200_NEW_TIP_AMT_MSG, szDisplayBuffer);
    vdDisplayAt(obDisp.inHomeCol, inAmtInputLine, szDisplayBuffer, CLR_EOL);


    //inResult = inGetAmount(szAmount, VS_TRUE, 0L, 999999999L, szDisplaySymbol);
    inResult = inCustGetAmount(szAmount, 0L, 999999999L, szDisplaySymbol, O3200_NEW_TIP_AMT_MSG);

    if (inResult >= 0) {
        lnBaseAmt = (pobTran->srBKey.lnTotalOfTransactionAmount - pobTran->srBRec.lnTaxAmount - pobTran->srBRec.lnTipAmount);

        lnOldTotalAmt = pobTran->srBKey.lnTotalOfTransactionAmount;
        lnOldTipAmt = pobTran->srBRec.lnTipAmount;
        pobTran->srBKey.lnTotalOfTransactionAmount = atol(szAmount);
        pobTran->srBRec.lnTipAmount = pobTran->srBKey.lnTotalOfTransactionAmount - lnBaseAmt - pobTran->srBRec.lnTaxAmount;
        //Kelvi_F2 --- start: add Excess Tip % checking
        //Check Excess Tip %
        pobTran->srBRec.lnBaseTransactionAmount = lnBaseAmt;
        if (fExcessiveTip(pobTran, pobTran->srBRec.lnTipAmount)) {
            vdDisplayMessageFromFile(TOO_MUCH_TIP_MSG, WARNING_MSG);
            pobTran->srBRec.lnTipAmount = lnOldTipAmt;
            pobTran->srBKey.lnTotalOfTransactionAmount = lnOldTotalAmt;
            return (VS_ERR);
        }
        //Kelvi_F2 --- end: add Excess Tip % checking
        //Tip is not allow more than the base
        if (pobTran->srBRec.lnTipAmount >= lnBaseAmt) {
            vdDisplayMessageFromFile(OUT_OF_RANGE_ERR_MSG/*CPAC_INVALID_TIP_MSG*/, WARNING_MSG);
            inResult = -1;
            memset(pobTran->szRespMsg, 0, RESP_MSG_SIZE); //Bug fix .. when txn not allowed donot show
            // approved...
            pobTran->srBRec.lnTipAmount = lnOldTipAmt;
            pobTran->srBKey.lnTotalOfTransactionAmount = lnOldTotalAmt;
            return(inResult);
        }

        //New total is smaller than the base
        if (pobTran->srBKey.lnTotalOfTransactionAmount < lnBaseAmt) {
            vdDisplayMessageFromFile(OUT_OF_RANGE_ERR_MSG, WARNING_MSG);
            pobTran->srBRec.lnTipAmount = lnOldTipAmt;
            pobTran->srBKey.lnTotalOfTransactionAmount = lnOldTotalAmt;
            return (VS_ERR);
        }

        inAllow = inCPACTotTransAmtAlwd(pobTran);
        if (inAllow != VS_SUCCESS) {
            pobTran->srBRec.lnTipAmount = lnOldTipAmt;
            pobTran->srBKey.lnTotalOfTransactionAmount = lnOldTotalAmt;
            return (VS_ERR);
        }
    }
    return (inResult);
}

/*********************************************************************************************
* @func int | inHKGMBatchReviewTipAdjust |
*
*       The tip amount is adjusted from the batch review function by entering the total amount.
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/

int inHKGMBatchReviewTipAdjust(TRANSACTION_OBJECT* pobTran) {
    char szAmount[AMT_SIZE + 1];
    char szDisplaySymbol[CUR_SYMBOL_SIZE + 1];
    char szDisplayBuffer[DISP_STR_LEN + 1];
    long lnBaseAmt;
    long lnTipAmt;
    int inResult;

    szAmount[0] = '\0';
    memset(szDisplayBuffer, 0, sizeof(szDisplayBuffer));

    /* pj1 save old amount first */
    pobTran->srBRec.lnOldTotalTransactionAmount = pobTran->srBKey.lnTotalOfTransactionAmount;
    pobTran->srBRec.lnOldTipAmount = pobTran->srBRec.lnTipAmount;

    /* Display old tip amount */
    sprintf(szAmount, SUBSTITUTE_LD, pobTran->srBRec.lnTipAmount);
    //vdPutDecPoint(szAmount); // LENIN ATL
    vdFormatAmount(szAmount, VS_FALSE);
    vdGetMessageFromFile(TIP_AMOUNT_MSG, szDisplayBuffer);

    vdDisplayAt(obDisp.inHomeCol, obDisp.inDetailLine, szDisplayBuffer, CLR_EOL);
    vdDispStrAtRight(szAmount, obDisp.inDetailLine, NO_CLEAR);

    /* Prompt for new tip amount */
    vdGetMessageFromFile(NEW_TIP_AMT_MSG, szDisplayBuffer);

    vdGetMessageFromFile(O3200_NEW_TIP_AMT_MSG, szDisplayBuffer);

    //      BT_TRACE ('I', szDisplayBuffer);
    do {
        szAmount[0] = '\0';
        vdDisplayAt(obDisp.inHomeCol, obDisp.inInputLine, szDisplayBuffer, CLR_EOL);
        strcpy(szDisplaySymbol, szGetCurSymbol());
        inResult = inGetAmount(szAmount, VS_TRUE, 0L, 999999999L, szDisplaySymbol);
        if (inResult >= 0) {
            lnTipAmt = atol(szAmount);

            if (fExcessiveTip(pobTran, lnTipAmt)) {
                // Must use these four lines of code below instead of
                // vdDisplayMessageFromFile(TOO_MUCH_TIP_MSG, ERROR_MSG);
                // because its logic doesn't return a value if the Clear Key
                // is pressed and we need to know so that the transaction
                // doesn't get approved if they pressed clear and are successful
                // in the inGetPwdFromUser() (i.e. no password prompt) because
                // they already logged in here with the Manager password.
                vdDisplayMessageFromFile(TOO_MUCH_TIP_MSG, STATUS_MSG);
                vdBeep();
                vdFlushKeyboardBuffer();
                inResult = inWaitKey(inGetIdleTimeOut());

                if (inResult != KEY_CANCEL) {
                    if (inGetPwdFromUser(ACCESS_WITH_MANAGER_PASSWORD, NO_PIT_INDEX) != VS_ESCAPE) {
                        lnBaseAmt = (pobTran->srBKey.lnTotalOfTransactionAmount - pobTran->srBRec.lnTaxAmount - pobTran->srBRec.lnTipAmount);
                        pobTran->srBKey.lnTotalOfTransactionAmount = atol(szAmount);
                        pobTran->srBRec.lnTipAmount = pobTran->srBKey.lnTotalOfTransactionAmount - lnBaseAmt - pobTran->srBRec.lnTaxAmount;
                        inResult = VS_SUCCESS;
                    } /* end if require manager password */
                    else {
                        inResult = VS_ESCAPE;
                        break;
                    }
                } /* end if not clear key */
                else {
                    // Try again
                    clrscr();
                    continue;
                }
            } /* end if excessive tip */
            else {
                lnBaseAmt = (pobTran->srBKey.lnTotalOfTransactionAmount - pobTran->srBRec.lnTaxAmount - pobTran->srBRec.lnTipAmount);
                pobTran->srBKey.lnTotalOfTransactionAmount = atol(szAmount);
                pobTran->srBRec.lnTipAmount = pobTran->srBKey.lnTotalOfTransactionAmount - lnBaseAmt - pobTran->srBRec.lnTaxAmount;
                inResult = VS_SUCCESS;
            } /* end else not excessive tip */
        } /* end if tip amount entry success */
        else
            break;
    } while (inResult != VS_SUCCESS && !act_kbd_pending_test(KEY_CANCEL));


    return (inResult);
}
#endif /* HKGM */
//Kelvin_F2 --- end: Tip Adjust Input By Total (Hong Kong Style)
VS_BOOL fchkrevfile(TRANSACTION_OBJECT* pobTran) {
    int inHostIndex;
    char stRevFileName[FILENAME_SIZE + 1];

    for (inHostIndex = 0; inHostIndex < MAX_HOSTS; ++inHostIndex) {
        vdGetReversalFileName(stRevFileName, inHostIndex);
        strcat(stRevFileName, ROC_FILE_EXTN);
        if (inChkFileExist(stRevFileName) == VS_SUCCESS)
            return(VS_FALSE);

        vdGetReversalFileName(stRevFileName, inHostIndex);
        strcat(stRevFileName, OFFLINE_FILE_EXTN);
        if (inChkFileExist(stRevFileName) == VS_SUCCESS)
            return(VS_FALSE);

        vdGetReversalFileName(stRevFileName, inHostIndex);
        strcat(stRevFileName, REVERSAL_FILE_EXTN);
        if (inChkFileExist(stRevFileName) == VS_SUCCESS)
            return(VS_FALSE);
    }
    return(VS_TRUE);
}

#undef CPAC_VPRINT_C
